diff --git a/google/google.go b/google/google.go index 82399b0..a48d5bf 100644 --- a/google/google.go +++ b/google/google.go @@ -89,6 +89,7 @@ func JWTConfigFromJSON(jsonKey []byte, scope ...string) (*jwt.Config, error) { Email string `json:"client_email"` PrivateKey string `json:"private_key"` PrivateKeyID string `json:"private_key_id"` + TokenURL string `json:"token_uri"` } if err := json.Unmarshal(jsonKey, &key); err != nil { return nil, err @@ -98,7 +99,10 @@ func JWTConfigFromJSON(jsonKey []byte, scope ...string) (*jwt.Config, error) { PrivateKey: []byte(key.PrivateKey), PrivateKeyID: key.PrivateKeyID, Scopes: scope, - TokenURL: JWTTokenURL, + TokenURL: key.TokenURL, + } + if config.TokenURL == "" { + config.TokenURL = JWTTokenURL } return config, nil } diff --git a/google/google_test.go b/google/google_test.go index 3046b05..287c699 100644 --- a/google/google_test.go +++ b/google/google_test.go @@ -32,6 +32,15 @@ var installedJSONKey = []byte(`{ }`) var jwtJSONKey = []byte(`{ + "private_key_id": "268f54e43a1af97cfc71731688434f45aca15c8b", + "private_key": "super secret key", + "client_email": "gopher@developer.gserviceaccount.com", + "client_id": "gopher.apps.googleusercontent.com", + "token_uri": "https://accounts.google.com/o/gophers/token", + "type": "service_account" +}`) + +var jwtJSONKeyNoTokenURL = []byte(`{ "private_key_id": "268f54e43a1af97cfc71731688434f45aca15c8b", "private_key": "super secret key", "client_email": "gopher@developer.gserviceaccount.com", @@ -91,6 +100,16 @@ func TestJWTConfigFromJSON(t *testing.T) { if got, want := strings.Join(conf.Scopes, ","), "scope1,scope2"; got != want { t.Errorf("Scopes = %q; want %q", got, want) } + if got, want := conf.TokenURL, "https://accounts.google.com/o/gophers/token"; got != want { + t.Errorf("TokenURL = %q; want %q", got, want) + } +} + +func TestJWTConfigFromJSONNoTokenURL(t *testing.T) { + conf, err := JWTConfigFromJSON(jwtJSONKeyNoTokenURL, "scope1", "scope2") + if err != nil { + t.Fatal(err) + } if got, want := conf.TokenURL, "https://accounts.google.com/o/oauth2/token"; got != want { t.Errorf("TokenURL = %q; want %q", got, want) }