google: support key ID in JWTAccessTokenSourceFromJSON
Change-Id: I20ffede5bf81aa4990afb2820561d5633cdb43a8 Reviewed-on: https://go-review.googlesource.com/24440 Reviewed-by: Chris Broadfoot <cbro@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
@@ -31,6 +31,14 @@ 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",
|
||||
"type": "service_account"
|
||||
}`)
|
||||
|
||||
func TestConfigFromJSON(t *testing.T) {
|
||||
conf, err := ConfigFromJSON(webJSONKey, "scope1", "scope2")
|
||||
if err != nil {
|
||||
@@ -65,3 +73,25 @@ func TestConfigFromJSON_Installed(t *testing.T) {
|
||||
t.Errorf("ClientID = %q; want %q", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestJWTConfigFromJSON(t *testing.T) {
|
||||
conf, err := JWTConfigFromJSON(jwtJSONKey, "scope1", "scope2")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got, want := conf.Email, "gopher@developer.gserviceaccount.com"; got != want {
|
||||
t.Errorf("Email = %q, want %q", got, want)
|
||||
}
|
||||
if got, want := string(conf.PrivateKey), "super secret key"; got != want {
|
||||
t.Errorf("PrivateKey = %q, want %q", got, want)
|
||||
}
|
||||
if got, want := conf.PrivateKeyID, "268f54e43a1af97cfc71731688434f45aca15c8b"; got != want {
|
||||
t.Errorf("PrivateKeyID = %q, want %q", got, want)
|
||||
}
|
||||
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/oauth2/token"; got != want {
|
||||
t.Errorf("TokenURL = %q; want %q", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user