forked from Mirrors/oauth2
Changing some nits.
Change-Id: I74140daa4acf876388f4f8ef83c475c1ae7d1865
This commit is contained in:
parent
8857346214
commit
990173083e
|
@ -31,25 +31,20 @@ type Config struct {
|
||||||
|
|
||||||
// TokenSource Returns an external account TokenSource struct. This is to be called by package google to construct a google.Credentials.
|
// TokenSource Returns an external account TokenSource struct. This is to be called by package google to construct a google.Credentials.
|
||||||
func (c *Config) TokenSource(ctx context.Context) oauth2.TokenSource {
|
func (c *Config) TokenSource(ctx context.Context) oauth2.TokenSource {
|
||||||
if c.ServiceAccountImpersonationURL == "" {
|
|
||||||
ts := tokenSource{
|
|
||||||
ctx: ctx,
|
|
||||||
conf: c,
|
|
||||||
}
|
|
||||||
return oauth2.ReuseTokenSource(nil, ts)
|
|
||||||
}
|
|
||||||
imp := impersonateTokenSource{
|
|
||||||
ctx: ctx,
|
|
||||||
url: c.ServiceAccountImpersonationURL,
|
|
||||||
scopes: c.Scopes,
|
|
||||||
}
|
|
||||||
ts := tokenSource{
|
ts := tokenSource{
|
||||||
ctx: ctx,
|
ctx: ctx,
|
||||||
conf: c,
|
conf: c,
|
||||||
}
|
}
|
||||||
ts.conf.ServiceAccountImpersonationURL = ""
|
if c.ServiceAccountImpersonationURL == "" {
|
||||||
|
return oauth2.ReuseTokenSource(nil, ts)
|
||||||
|
}
|
||||||
ts.conf.Scopes = []string{"https://www.googleapis.com/auth/cloud-platform"}
|
ts.conf.Scopes = []string{"https://www.googleapis.com/auth/cloud-platform"}
|
||||||
imp.ts = oauth2.ReuseTokenSource(nil, ts)
|
imp := impersonateTokenSource{
|
||||||
|
ctx: ctx,
|
||||||
|
url: c.ServiceAccountImpersonationURL,
|
||||||
|
scopes: c.Scopes,
|
||||||
|
ts: oauth2.ReuseTokenSource(nil, ts),
|
||||||
|
}
|
||||||
return oauth2.ReuseTokenSource(nil, imp)
|
return oauth2.ReuseTokenSource(nil, imp)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,7 @@ type impersonateTokenSource struct {
|
||||||
scopes []string
|
scopes []string
|
||||||
}
|
}
|
||||||
|
|
||||||
// impersonate performs the exchange to get a temporary service account
|
// Token performs the exchange to get a temporary service account
|
||||||
func (its impersonateTokenSource) Token() (*oauth2.Token, error) {
|
func (its impersonateTokenSource) Token() (*oauth2.Token, error) {
|
||||||
reqBody := generateAccessTokenReq{
|
reqBody := generateAccessTokenReq{
|
||||||
Lifetime: "3600s",
|
Lifetime: "3600s",
|
||||||
|
|
Loading…
Reference in New Issue