@@ -113,13 +113,20 @@ import (
113
113
"net/http"
114
114
"regexp"
115
115
"strconv"
116
+ "strings"
116
117
"time"
117
118
118
119
"golang.org/x/oauth2"
119
120
"golang.org/x/oauth2/google/internal/impersonate"
120
121
"golang.org/x/oauth2/google/internal/stsexchange"
121
122
)
122
123
124
+ const (
125
+ universeDomainPlaceholder = "UNIVERSE_DOMAIN"
126
+ defaultTokenURL = "https://sts.UNIVERSE_DOMAIN/v1/token"
127
+ defaultUniverseDomain = "googleapis.com"
128
+ )
129
+
123
130
// now aliases time.Now for testing
124
131
var now = func () time.Time {
125
132
return time .Now ().UTC ()
@@ -139,7 +146,9 @@ type Config struct {
139
146
// Required.
140
147
SubjectTokenType string
141
148
// TokenURL is the STS token exchange endpoint. If not provided, will default to
142
- // https://sts.googleapis.com/v1/token. Optional.
149
+ // https://sts.UNIVERSE_DOMAIN/v1/token, with UNIVERSE_DOMAIN set to the
150
+ // default service domain googleapis.com unless UniverseDomain is set.
151
+ // Optional.
143
152
TokenURL string
144
153
// TokenInfoURL is the token_info endpoint used to retrieve the account related information (
145
154
// user attributes like account identifier, eg. email, username, uid, etc). This is
@@ -177,6 +186,10 @@ type Config struct {
177
186
// AwsSecurityCredentialsSupplier is an AWS Security Credential supplier for AWS credentials.
178
187
// One of SubjectTokenSupplier, AWSSecurityCredentialSupplier or CredentialSource must be provided. Optional.
179
188
AwsSecurityCredentialsSupplier AwsSecurityCredentialsSupplier
189
+ // UniverseDomain is the default service domain for a given Cloud universe.
190
+ // This value will be used in the default STS token URL. The default value
191
+ // is "googleapis.com". It will not be used if TokenURL is set. Optional.
192
+ UniverseDomain string
180
193
}
181
194
182
195
var (
@@ -246,9 +259,8 @@ func (c *Config) tokenSource(ctx context.Context, scheme string) (oauth2.TokenSo
246
259
247
260
// Subject token file types.
248
261
const (
249
- fileTypeText = "text"
250
- fileTypeJSON = "json"
251
- defaultTokenUrl = "https://sts.googleapis.com/v1/token"
262
+ fileTypeText = "text"
263
+ fileTypeJSON = "json"
252
264
)
253
265
254
266
// Format contains information needed to retireve a subject token for URL or File sourced credentials.
@@ -336,11 +348,20 @@ type SupplierOptions struct {
336
348
SubjectTokenType string
337
349
}
338
350
351
+ // tokenURL returns the default STS token endpoint with the configured universe
352
+ // domain.
353
+ func (c * Config ) tokenURL () string {
354
+ if c .UniverseDomain == "" {
355
+ return strings .Replace (defaultTokenURL , universeDomainPlaceholder , defaultUniverseDomain , 1 )
356
+ }
357
+ return strings .Replace (defaultTokenURL , universeDomainPlaceholder , c .UniverseDomain , 1 )
358
+ }
359
+
339
360
// parse determines the type of CredentialSource needed.
340
361
func (c * Config ) parse (ctx context.Context ) (baseCredentialSource , error ) {
341
362
//set Defaults
342
363
if c .TokenURL == "" {
343
- c .TokenURL = defaultTokenUrl
364
+ c .TokenURL = c . tokenURL ()
344
365
}
345
366
supplierOptions := SupplierOptions {Audience : c .Audience , SubjectTokenType : c .SubjectTokenType }
346
367
0 commit comments