Skip to content
ecdsa.com
coreos/go-oidc (Go)Go

Error message

oidc: expected audience "api-client" got ["web-client"]

coreos/go-oidc (Go) — IDTokenVerifier.Verify

What it means

The ID token is signed by the right provider, but its `aud` claim does not contain the `ClientID` you configured in `oidc.Config`. go-oidc implements the OpenID Connect rule that an ID token is only valid for the client it was issued to; the first quoted value is your `ClientID`, the list is the token's audiences.

Why it happens

How to fix it

  1. 1.

    Use the client ID of the app that signed the user in

    For ID tokens, configure exactly the client ID the token was issued to.

    go
    verifier := provider.Verifier(&oidc.Config{
    	ClientID: os.Getenv("OIDC_CLIENT_ID"), // the client the user signed in to; must equal the token's aud
    })
    idToken, err := verifier.Verify(ctx, rawIDToken)
  2. 2.

    For API access tokens, check the API audience yourself

    `SkipClientIDCheck` only disables the built-in client-ID comparison. Replace it with an explicit check for your API's identifier — never skip audience validation altogether.

    go
    // Verifying a JWT access token for an API: check signature/issuer/expiry here,
    // then check the API audience yourself.
    verifier := provider.Verifier(&oidc.Config{SkipClientIDCheck: true})
    tok, err := verifier.Verify(ctx, rawAccessToken)
    if err != nil {
    	return err
    }
    if !slices.Contains(tok.Audience, "https://api.example.com") {
    	return errors.New("token not issued for this API")
    }

Related errors

Browse the full signature error database