99 "fmt"
1010 "io"
1111 "net/http"
12+ "slices"
1213 "strings"
1314 "time"
1415
@@ -50,9 +51,10 @@ type KeySet interface {
5051
5152// IDTokenVerifier provides verification for ID Tokens.
5253type IDTokenVerifier struct {
53- keySet KeySet
54- config * Config
55- issuer string
54+ keySet KeySet
55+ config * Config
56+ issuer string
57+ alternativeIssuer []string
5658}
5759
5860// NewVerifier returns a verifier manually constructed from a key set and issuer URL.
@@ -71,8 +73,8 @@ type IDTokenVerifier struct {
7173//
7274// keySet := &oidc.StaticKeySet{PublicKeys: []crypto.PublicKey{pub1, pub2}}
7375// 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 }
76+ func NewVerifier (issuerURL string , keySet KeySet , config * Config , alternativeIssuer ... string ) * IDTokenVerifier {
77+ return & IDTokenVerifier {keySet : keySet , config : config , issuer : issuerURL , alternativeIssuer : alternativeIssuer }
7678}
7779
7880// Config is the configuration for an IDTokenVerifier.
@@ -142,7 +144,7 @@ func (p *Provider) newVerifier(keySet KeySet, config *Config) *IDTokenVerifier {
142144 cp .SupportedSigningAlgs = p .algorithms
143145 config = cp
144146 }
145- return NewVerifier (p .issuer , keySet , config )
147+ return NewVerifier (p .issuer , keySet , config , p . alternativeIssuer ... )
146148}
147149
148150func parseJWT (p string ) ([]byte , error ) {
@@ -257,14 +259,16 @@ func (v *IDTokenVerifier) Verify(ctx context.Context, rawIDToken string) (*IDTok
257259 }
258260
259261 // Check issuer.
260- if ! v .config .SkipIssuerCheck && t .Issuer != v .issuer {
262+ v .alternativeIssuer = append (v .alternativeIssuer , v .issuer )
263+
264+ if ! v .config .SkipIssuerCheck && ! slices .Contains (v .alternativeIssuer , t .Issuer ) {
261265 // Google sometimes returns "accounts.google.com" as the issuer claim instead of
262266 // the required "https://accounts.google.com". Detect this case and allow it only
263267 // for Google.
264268 //
265269 // We will not add hooks to let other providers go off spec like this.
266270 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 )
271+ return nil , fmt .Errorf ("oidc: id token issued by a different provider, expected one of %v got %q" , v .alternativeIssuer , t .Issuer )
268272 }
269273 }
270274
0 commit comments