Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(idtoken): add support for external_account #1897

Merged
merged 3 commits into from Mar 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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