fix(auth/oauth2adapt): adapt Token Types to be translated (#9801)
Related: #9800
diff --git a/auth/oauth2adapt/go.mod b/auth/oauth2adapt/go.mod
index f30b79f..517077c 100644
--- a/auth/oauth2adapt/go.mod
+++ b/auth/oauth2adapt/go.mod
@@ -3,7 +3,7 @@
go 1.19
require (
- cloud.google.com/go/auth v0.2.0
+ cloud.google.com/go/auth v0.2.1
github.com/google/go-cmp v0.6.0
golang.org/x/oauth2 v0.19.0
)
diff --git a/auth/oauth2adapt/go.sum b/auth/oauth2adapt/go.sum
index 8b29eb2..9d15701 100644
--- a/auth/oauth2adapt/go.sum
+++ b/auth/oauth2adapt/go.sum
@@ -1,5 +1,5 @@
-cloud.google.com/go/auth v0.2.0 h1:y6oTcpMSbOcXbwYgUUrvI+mrQ2xbrcdpPgtVbCGTLTk=
-cloud.google.com/go/auth v0.2.0/go.mod h1:+yb+oy3/P0geX6DLKlqiGHARGR6EX2GRtYCzWOCQSbU=
+cloud.google.com/go/auth v0.2.1 h1:RMl6PI2MH1Qc3CM7XNJJHGwbC4WHQppSAjL0Cvu/M/g=
+cloud.google.com/go/auth v0.2.1/go.mod h1:khQRBNrvNoHiHhV1iu2x8fSnlNbCaVHilznW5MAI5GY=
cloud.google.com/go/compute/metadata v0.3.0 h1:Tz+eQXMEqDIKRsmY3cHTL6FVaynIjX2QxYC4trgAKZc=
cloud.google.com/go/compute/metadata v0.3.0/go.mod h1:zFmK7XCadkQkj6TtorcaGlCW1hT1fIilQDwofLpJ20k=
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE=
diff --git a/auth/oauth2adapt/oauth2adapt.go b/auth/oauth2adapt/oauth2adapt.go
index 897b59f..9835ac5 100644
--- a/auth/oauth2adapt/oauth2adapt.go
+++ b/auth/oauth2adapt/oauth2adapt.go
@@ -49,6 +49,7 @@
}
return &auth.Token{
Value: tok.AccessToken,
+ Type: tok.Type(),
Expiry: tok.Expiry,
}, nil
}
@@ -77,6 +78,7 @@
}
return &oauth2.Token{
AccessToken: tok.Value,
+ TokenType: tok.Type,
Expiry: tok.Expiry,
}, nil
}
diff --git a/auth/oauth2adapt/oauth2adapt_test.go b/auth/oauth2adapt/oauth2adapt_test.go
index 5ea923b..d408c90 100644
--- a/auth/oauth2adapt/oauth2adapt_test.go
+++ b/auth/oauth2adapt/oauth2adapt_test.go
@@ -29,12 +29,12 @@
func TestTokenProviderFromTokenSource(t *testing.T) {
tests := []struct {
name string
- token string
+ token *oauth2.Token
err error
}{
{
name: "working token",
- token: "fakeToken",
+ token: &oauth2.Token{AccessToken: "fakeToken", TokenType: "Basic"},
err: nil,
},
{
@@ -72,8 +72,11 @@
}
return
}
- if tok.Value != tt.token {
- t.Errorf("got %q, want %q", tok.Value, tt.token)
+ if tok.Value != tt.token.AccessToken {
+ t.Errorf("got %q, want %q", tok.Value, tt.token.AccessToken)
+ }
+ if tok.Type != tt.token.TokenType {
+ t.Errorf("got %q, want %q", tok.Type, tt.token.TokenType)
}
})
}
@@ -82,13 +85,16 @@
func TestTokenSourceFromTokenProvider(t *testing.T) {
tests := []struct {
name string
- token string
+ token *auth.Token
err error
}{
{
- name: "working token",
- token: "fakeToken",
- err: nil,
+ name: "working token",
+ token: &auth.Token{
+ Value: "fakeToken",
+ Type: "Basic",
+ },
+ err: nil,
},
{
name: "coverts err",
@@ -134,8 +140,11 @@
}
return
}
- if tok.AccessToken != tt.token {
- t.Errorf("got %q, want %q", tok.AccessToken, tt.token)
+ if tok.AccessToken != tt.token.Value {
+ t.Errorf("got %q, want %q", tok.AccessToken, tt.token.Value)
+ }
+ if tok.TokenType != tt.token.Type {
+ t.Errorf("got %q, want %q", tok.TokenType, tt.token.Type)
}
})
}
@@ -145,7 +154,7 @@
ctx := context.Background()
inputCreds := &google.Credentials{
ProjectID: "test_project",
- TokenSource: tokenSource{token: "token"},
+ TokenSource: tokenSource{token: &oauth2.Token{AccessToken: "token"}},
JSON: []byte("json"),
UniverseDomainProvider: func() (string, error) {
return "domain", nil
@@ -197,7 +206,7 @@
ProjectIDProvider: auth.CredentialsPropertyFunc(func(ctx context.Context) (string, error) {
return "project", nil
}),
- TokenProvider: tokenProvider{token: "token"},
+ TokenProvider: tokenProvider{token: &auth.Token{Value: "token"}},
JSON: []byte("json"),
UniverseDomainProvider: auth.CredentialsPropertyFunc(func(ctx context.Context) (string, error) {
return "domain", nil
@@ -244,7 +253,7 @@
}
type tokenSource struct {
- token string
+ token *oauth2.Token
err error
}
@@ -253,12 +262,13 @@
return nil, ts.err
}
return &oauth2.Token{
- AccessToken: ts.token,
+ AccessToken: ts.token.AccessToken,
+ TokenType: ts.token.TokenType,
}, nil
}
type tokenProvider struct {
- token string
+ token *auth.Token
err error
}
@@ -267,6 +277,7 @@
return nil, tp.err
}
return &auth.Token{
- Value: tp.token,
+ Value: tp.token.Value,
+ Type: tp.token.Type,
}, nil
}