Skip to content

Commit

Permalink
Add support for external_account.
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.
  • Loading branch information
Senthil Kumar Karuppiah committed Mar 8, 2023
1 parent 9f18671 commit 76e5c98
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
external_account
)

// 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, external_account:
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 external_account
default:
return unknownCredType
}
Expand Down

0 comments on commit 76e5c98

Please sign in to comment.