@@ -66,6 +66,14 @@ type Config struct {
6666 // request. If empty, the value of TokenURL is used as the
6767 // intended audience.
6868 Audience string
69+
70+ // PrivateClaims optionally specifies custom private claims in the JWT.
71+ // See http://tools.ietf.org/html/draft-jones-json-web-token-10#section-4.3
72+ PrivateClaims map [string ]interface {}
73+
74+ // UseIDToken optionally specifies whether ID token should be used instead
75+ // of access token when the server returns both.
76+ UseIDToken bool
6977}
7078
7179// TokenSource returns a JWT TokenSource using the configuration
@@ -97,9 +105,10 @@ func (js jwtSource) Token() (*oauth2.Token, error) {
97105 }
98106 hc := oauth2 .NewClient (js .ctx , nil )
99107 claimSet := & jws.ClaimSet {
100- Iss : js .conf .Email ,
101- Scope : strings .Join (js .conf .Scopes , " " ),
102- Aud : js .conf .TokenURL ,
108+ Iss : js .conf .Email ,
109+ Scope : strings .Join (js .conf .Scopes , " " ),
110+ Aud : js .conf .TokenURL ,
111+ PrivateClaims : js .conf .PrivateClaims ,
103112 }
104113 if subject := js .conf .Subject ; subject != "" {
105114 claimSet .Sub = subject
@@ -166,5 +175,11 @@ func (js jwtSource) Token() (*oauth2.Token, error) {
166175 }
167176 token .Expiry = time .Unix (claimSet .Exp , 0 )
168177 }
178+ if js .conf .UseIDToken {
179+ if tokenRes .IDToken == "" {
180+ return nil , fmt .Errorf ("oauth2: response doesn't have JWT token" )
181+ }
182+ token .AccessToken = tokenRes .IDToken
183+ }
169184 return token , nil
170185}
0 commit comments