@@ -50,9 +50,10 @@ type KeySet interface {
50
50
51
51
// IDTokenVerifier provides verification for ID Tokens.
52
52
type IDTokenVerifier struct {
53
- keySet KeySet
54
- config * Config
55
- issuer string
53
+ keySet KeySet
54
+ config * Config
55
+ issuer string
56
+ alternativeIssuer []string
56
57
}
57
58
58
59
// NewVerifier returns a verifier manually constructed from a key set and issuer URL.
@@ -71,8 +72,8 @@ type IDTokenVerifier struct {
71
72
//
72
73
// keySet := &oidc.StaticKeySet{PublicKeys: []crypto.PublicKey{pub1, pub2}}
73
74
// verifier := oidc.NewVerifier("https://accounts.google.com", keySet, config)
74
- func NewVerifier (issuerURL string , keySet KeySet , config * Config ) * IDTokenVerifier {
75
- return & IDTokenVerifier {keySet : keySet , config : config , issuer : issuerURL }
75
+ func NewVerifier (issuerURL string , keySet KeySet , config * Config , alternativeIssuer ... string ) * IDTokenVerifier {
76
+ return & IDTokenVerifier {keySet : keySet , config : config , issuer : issuerURL , alternativeIssuer : alternativeIssuer }
76
77
}
77
78
78
79
// Config is the configuration for an IDTokenVerifier.
@@ -142,7 +143,7 @@ func (p *Provider) newVerifier(keySet KeySet, config *Config) *IDTokenVerifier {
142
143
cp .SupportedSigningAlgs = p .algorithms
143
144
config = cp
144
145
}
145
- return NewVerifier (p .issuer , keySet , config )
146
+ return NewVerifier (p .issuer , p . remoteKeySet , config , p . alternativeIssuer ... )
146
147
}
147
148
148
149
func parseJWT (p string ) ([]byte , error ) {
@@ -257,14 +258,15 @@ func (v *IDTokenVerifier) Verify(ctx context.Context, rawIDToken string) (*IDTok
257
258
}
258
259
259
260
// Check issuer.
260
- if ! v .config .SkipIssuerCheck && t .Issuer != v .issuer {
261
+ issuerStr := strings .Join (append (v .alternativeIssuer , v .issuer ), " " )
262
+ if ! v .config .SkipIssuerCheck && ! strings .Contains (issuerStr , t .Issuer ) {
261
263
// Google sometimes returns "accounts.google.com" as the issuer claim instead of
262
264
// the required "https://accounts.google.com". Detect this case and allow it only
263
265
// for Google.
264
266
//
265
267
// We will not add hooks to let other providers go off spec like this.
266
268
if ! (v .issuer == issuerGoogleAccounts && t .Issuer == issuerGoogleAccountsNoScheme ) {
267
- return nil , fmt .Errorf ("oidc: id token issued by a different provider, expected %q got %q" , v . issuer , t .Issuer )
269
+ return nil , fmt .Errorf ("oidc: id token issued by a different provider, expected one of %q got %q" , issuerStr , t .Issuer )
268
270
}
269
271
}
270
272
0 commit comments