Skip to content

Commit

Permalink
feat(idtoken): add support for external_account (#1897)
Browse files Browse the repository at this point in the history
* Also fix a bug for impersonated_service_account
    * When creds are passed with WithCredentialsFile(), it doesn't work.
    * Pass the option when creating the token source.
* Fixes PR #1879
  • Loading branch information
senthilkumarkj committed Mar 14, 2023
1 parent 65cafd4 commit 64b6ee4
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions idtoken/idtoken.go
Expand Up @@ -34,6 +34,7 @@ const (
unknownCredType credentialsType = iota
serviceAccount
impersonatedServiceAccount
externalAccount
)

// NewClient creates a HTTP Client that automatically adds an ID token to each
Expand Down Expand Up @@ -139,7 +140,7 @@ func tokenSourceFromBytes(ctx context.Context, data []byte, audience string, ds
return nil, err
}
return oauth2.ReuseTokenSource(tok, ts), nil
case impersonatedServiceAccount:
case impersonatedServiceAccount, externalAccount:
type url struct {
ServiceAccountImpersonationURL string `json:"service_account_impersonation_url"`
}
Expand All @@ -155,7 +156,7 @@ func tokenSourceFromBytes(ctx context.Context, data []byte, audience string, ds
TargetPrincipal: account,
IncludeEmail: true,
}
ts, err := impersonate.IDTokenSource(ctx, config)
ts, err := impersonate.IDTokenSource(ctx, config, option.WithCredentialsJSON(data))
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -188,6 +189,8 @@ func parseCredType(typeString string) credentialsType {
return serviceAccount
case "impersonated_service_account":
return impersonatedServiceAccount
case "external_account":
return externalAccount
default:
return unknownCredType
}
Expand Down

0 comments on commit 64b6ee4

Please sign in to comment.