@@ -38,9 +38,10 @@ type KeySet interface {
38
38
39
39
// IDTokenVerifier provides verification for ID Tokens.
40
40
type IDTokenVerifier struct {
41
- keySet KeySet
42
- config * Config
43
- issuer string
41
+ keySet KeySet
42
+ config * Config
43
+ issuer string
44
+ alternativeIssuer []string
44
45
}
45
46
46
47
// NewVerifier returns a verifier manually constructed from a key set and issuer URL.
@@ -65,8 +66,8 @@ type IDTokenVerifier struct {
65
66
// // Verifier uses the custom KeySet implementation.
66
67
// verifier := oidc.NewVerifier("https://auth.example.com", keySet, config)
67
68
//
68
- func NewVerifier (issuerURL string , keySet KeySet , config * Config ) * IDTokenVerifier {
69
- return & IDTokenVerifier {keySet : keySet , config : config , issuer : issuerURL }
69
+ func NewVerifier (issuerURL string , keySet KeySet , config * Config , alternativeIssuer ... string ) * IDTokenVerifier {
70
+ return & IDTokenVerifier {keySet : keySet , config : config , issuer : issuerURL , alternativeIssuer : alternativeIssuer }
70
71
}
71
72
72
73
// Config is the configuration for an IDTokenVerifier.
@@ -114,7 +115,7 @@ func (p *Provider) Verifier(config *Config) *IDTokenVerifier {
114
115
cp .SupportedSigningAlgs = p .algorithms
115
116
config = cp
116
117
}
117
- return NewVerifier (p .issuer , p .remoteKeySet , config )
118
+ return NewVerifier (p .issuer , p .remoteKeySet , config , p . alternativeIssuer ... )
118
119
}
119
120
120
121
func parseJWT (p string ) ([]byte , error ) {
@@ -249,14 +250,15 @@ func (v *IDTokenVerifier) Verify(ctx context.Context, rawIDToken string) (*IDTok
249
250
}
250
251
251
252
// Check issuer.
252
- if ! v .config .SkipIssuerCheck && t .Issuer != v .issuer {
253
+ issuerStr := strings .Join (append (v .alternativeIssuer , v .issuer ), " " )
254
+ if ! v .config .SkipIssuerCheck && ! strings .Contains (issuerStr , t .Issuer ) {
253
255
// Google sometimes returns "accounts.google.com" as the issuer claim instead of
254
256
// the required "https://accounts.google.com". Detect this case and allow it only
255
257
// for Google.
256
258
//
257
259
// We will not add hooks to let other providers go off spec like this.
258
260
if ! (v .issuer == issuerGoogleAccounts && t .Issuer == issuerGoogleAccountsNoScheme ) {
259
- return nil , fmt .Errorf ("oidc: id token issued by a different provider, expected %q got %q" , v . issuer , t .Issuer )
261
+ return nil , fmt .Errorf ("oidc: id token issued by a different provider, expected one of %q got %q" , issuerStr , t .Issuer )
260
262
}
261
263
}
262
264
0 commit comments