Skip to content

Commit 885f294

Browse files
andyrzhaoshinfan
authored andcommitted
google: Add support for OAuth2 token exchange over mTLS
With Context Aware Access enabled, users must use the endpoint "https://oauth2.mtls.googleapis.com/token" for token exchange. This PR adds support for runtime configuration of the OAuth2 token endpoint (as determined by the caller). If using the mTLS oauth2 endpoint, the caller will also need to specify an mTLS-enabled HTTPClient via the "context" mechanism for use by the OAuth2 transport. Change-Id: Ic83342ec1d224d3acdabf00d863249330424fc54 GitHub-Last-Rev: 07e4849 GitHub-Pull-Request: #630 Reviewed-on: https://go-review.googlesource.com/c/oauth2/+/470396 Run-TryBot: Matthew Hickford <[email protected]> Reviewed-by: Shin Fan <[email protected]> Run-TryBot: Shin Fan <[email protected]> Reviewed-by: Matthew Hickford <[email protected]> Reviewed-by: Andy Zhao <[email protected]> TryBot-Result: Gopher Robot <[email protected]>
1 parent 6f9c1a1 commit 885f294

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

google/default.go

+4
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ type CredentialsParams struct {
6262

6363
// PKCE is used to support PKCE flow. Optional for 3LO flow.
6464
PKCE *authhandler.PKCEParams
65+
66+
// The OAuth2 TokenURL default override. This value overrides the default TokenURL,
67+
// unless explicitly specified by the credentials config file. Optional.
68+
TokenURL string
6569
}
6670

6771
func (params CredentialsParams) deepCopy() CredentialsParams {

google/google.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ var Endpoint = oauth2.Endpoint{
2626
AuthStyle: oauth2.AuthStyleInParams,
2727
}
2828

29+
// MTLSTokenURL is Google's OAuth 2.0 default mTLS endpoint.
30+
const MTLSTokenURL = "https://oauth2.mtls.googleapis.com/token"
31+
2932
// JWTTokenURL is Google's OAuth 2.0 token URL to use with the JWT flow.
3033
const JWTTokenURL = "https://oauth2.googleapis.com/token"
3134

@@ -172,7 +175,11 @@ func (f *credentialsFile) tokenSource(ctx context.Context, params CredentialsPar
172175
cfg.Endpoint.AuthURL = Endpoint.AuthURL
173176
}
174177
if cfg.Endpoint.TokenURL == "" {
175-
cfg.Endpoint.TokenURL = Endpoint.TokenURL
178+
if params.TokenURL != "" {
179+
cfg.Endpoint.TokenURL = params.TokenURL
180+
} else {
181+
cfg.Endpoint.TokenURL = Endpoint.TokenURL
182+
}
176183
}
177184
tok := &oauth2.Token{RefreshToken: f.RefreshToken}
178185
return cfg.TokenSource(ctx, tok), nil

0 commit comments

Comments
 (0)