mirror of https://github.com/docker/compose.git
Merge pull request #355 from docker/fix_windows_login
Fix windows login
This commit is contained in:
commit
2e867f40d7
|
@ -134,6 +134,7 @@ func (login AzureLoginService) Login(ctx context.Context, requestedTenantID stri
|
|||
if redirectURL == "" {
|
||||
return errors.Wrap(errdefs.ErrLoginFailed, "empty redirect URL")
|
||||
}
|
||||
|
||||
if err = login.apiHelper.openAzureLoginPage(redirectURL); err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -23,9 +23,10 @@ import (
|
|||
"math/rand"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os/exec"
|
||||
"runtime"
|
||||
"strings"
|
||||
|
||||
"github.com/pkg/browser"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
|
@ -40,7 +41,7 @@ type azureAPIHelper struct{}
|
|||
func (helper azureAPIHelper) openAzureLoginPage(redirectURL string) error {
|
||||
state := randomString("", 10)
|
||||
authURL := fmt.Sprintf(authorizeFormat, clientID, redirectURL, state, scopes)
|
||||
return browser.OpenURL(authURL)
|
||||
return openbrowser(authURL)
|
||||
}
|
||||
|
||||
func (helper azureAPIHelper) queryAuthorizationAPI(authorizationURL string, authorizationHeader string) ([]byte, int, error) {
|
||||
|
@ -79,6 +80,19 @@ func (helper azureAPIHelper) queryToken(data url.Values, tenantID string) (azure
|
|||
return token, nil
|
||||
}
|
||||
|
||||
func openbrowser(url string) error {
|
||||
switch runtime.GOOS {
|
||||
case "linux":
|
||||
return exec.Command("xdg-open", url).Start()
|
||||
case "windows":
|
||||
return exec.Command("rundll32", "url.dll,FileProtocolHandler", url).Start()
|
||||
case "darwin":
|
||||
return exec.Command("open", url).Start()
|
||||
default:
|
||||
return fmt.Errorf("unsupported platform")
|
||||
}
|
||||
}
|
||||
|
||||
var (
|
||||
letterRunes = []rune("abcdefghijklmnopqrstuvwxyz123456789")
|
||||
)
|
||||
|
|
1
go.mod
1
go.mod
|
@ -39,7 +39,6 @@ require (
|
|||
github.com/opencontainers/go-digest v1.0.0
|
||||
github.com/opencontainers/image-spec v1.0.1 // indirect
|
||||
github.com/opencontainers/runc v0.1.1 // indirect
|
||||
github.com/pkg/browser v0.0.0-20180916011732-0a3d74bf9ce4
|
||||
github.com/pkg/errors v0.9.1
|
||||
github.com/robpike/filter v0.0.0-20150108201509-2984852a2183
|
||||
github.com/sirupsen/logrus v1.6.0
|
||||
|
|
2
go.sum
2
go.sum
|
@ -247,8 +247,6 @@ github.com/opencontainers/runc v0.1.1/go.mod h1:qT5XzbpPznkRYVz/mWwUaVBUv2rmF59P
|
|||
github.com/opencontainers/runtime-spec v0.1.2-0.20190507144316-5b71a03e2700 h1:eNUVfm/RFLIi1G7flU5/ZRTHvd4kcVuzfRnL6OFlzCI=
|
||||
github.com/opencontainers/runtime-spec v0.1.2-0.20190507144316-5b71a03e2700/go.mod h1:jwyrGlmzljRJv/Fgzds9SsS/C5hL+LL3ko9hs6T5lQ0=
|
||||
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
|
||||
github.com/pkg/browser v0.0.0-20180916011732-0a3d74bf9ce4 h1:49lOXmGaUpV9Fz3gd7TFZY106KVlPVa5jcYD1gaQf98=
|
||||
github.com/pkg/browser v0.0.0-20180916011732-0a3d74bf9ce4/go.mod h1:4OwLy04Bl9Ef3GJJCoec+30X3LQs/0/m4HFRt/2LUSA=
|
||||
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pkg/errors v0.8.1-0.20171018195549-f15c970de5b7/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
|
|
Loading…
Reference in New Issue