Skip to content

Commit

Permalink
feat(idtoken):Allow format options
Browse files Browse the repository at this point in the history
Added field CustomFormat to DialSettings in internal/settings.go
Added field format to computerIDTokenSource in idtoken/compute.go
Function computeTokenSource now sets field format to full, and if ds.CustomFormat != "" overwrites the field
Method Token now uses c.format instead of string literal "full"

Fixes googleapis#542
  • Loading branch information
eisandbar committed Aug 16, 2022
1 parent e0ad8e4 commit a482422
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
7 changes: 6 additions & 1 deletion idtoken/compute.go
Expand Up @@ -23,6 +23,10 @@ func computeTokenSource(audience string, ds *internal.DialSettings) (oauth2.Toke
}
ts := computeIDTokenSource{
audience: audience,
format: "full",
}
if ds.CustomFormat != "" {
ts.format = ds.CustomFormat
}
tok, err := ts.Token()
if err != nil {
Expand All @@ -33,12 +37,13 @@ func computeTokenSource(audience string, ds *internal.DialSettings) (oauth2.Toke

type computeIDTokenSource struct {
audience string
format string
}

func (c computeIDTokenSource) Token() (*oauth2.Token, error) {
v := url.Values{}
v.Set("audience", c.audience)
v.Set("format", "full")
v.Set("format", c.format)
urlSuffix := "instance/service-accounts/default/identity?" + v.Encode()
res, err := metadata.Get(urlSuffix)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions internal/settings.go
Expand Up @@ -47,6 +47,7 @@ type DialSettings struct {
ImpersonationConfig *impersonate.Config
EnableDirectPath bool
AllowNonDefaultServiceAccount bool
CustomFormat string

// Google API system parameters. For more information please read:
// https://cloud.google.com/apis/docs/system-parameters
Expand Down

0 comments on commit a482422

Please sign in to comment.