Skip to content

Commit

Permalink
Added default auth & token URLs instead from the wellknownfile (googl…
Browse files Browse the repository at this point in the history
…e#46)

* Added default auth & token URLs instead from the wellknownfile

* Updated with ADC information

* Falling back to default URLs only if file URLs are empty
  • Loading branch information
spothala authored and shinfan committed Aug 30, 2018
1 parent 524e4ee commit df8e0fc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
4 changes: 4 additions & 0 deletions go/sgauth/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ need to specify the `scope` value.
will try to look for your service account JSON file at the default path --- the path specified
by the `$GOOGLE_APPLICATION_CREDENTIAL` environment variable.

- __Authorized User__: If no above conditions are defined and you can still auth to google by genearating
ADC with command `gcloud auth application-default login`. This will store ADC at wellknown path
`~/.config/gcloud/application_default_credentials.json`

Protocols
---------

Expand Down
16 changes: 14 additions & 2 deletions go/sgauth/credentials/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ import (
// DefaultTokenURL is Google's OAuth 2.0 token URL to use with the JWT flow.
const DefaultTokenURL = "https://accounts.google.com/o/oauth2/token"

// DefaultAuthURL is Google's OAuth 2.0 Auth URL to use with the 2LO flow.
const DefaultAuthURL = "https://accounts.google.com/o/oauth2/auth"

// JSON key file types.
const (
ServiceAccountKey = "service_account"
Expand Down Expand Up @@ -85,13 +88,22 @@ func (f *File) TokenSource(ctx context.Context, scopes []string,
cfg := JWTConfigFromFile(f, scopes)
return cfg.TokenSource(ctx), nil
case UserCredentialsKey:
authURL := f.AuthURL
tokenURL := f.TokenURL
// Falling back to default URLs only if file URLs are empty
if authURL == "" {
authURL = DefaultAuthURL
}
if tokenURL == "" {
tokenURL = DefaultTokenURL
}
cfg := &internal.Config{
ClientID: f.ClientID,
ClientSecret: f.ClientSecret,
Scopes: scopes,
Endpoint: internal.Endpoint{
AuthURL: f.AuthURL,
TokenURL: f.TokenURL,
AuthURL: authURL,
TokenURL: tokenURL,
},
}
tok := &internal.Token{RefreshToken: f.RefreshToken}
Expand Down

0 comments on commit df8e0fc

Please sign in to comment.