firebase / firebase-js-sdk

Firebase Javascript SDK
https://firebase.google.com/docs/web/setup
Other
4.74k stars 868 forks source link

MISSING_OR_INVALID_NONCE : The nonce in ID Token does not match the SHA256 hash of the raw nonce in the request #8207

Open adityapol7711 opened 3 weeks ago

adityapol7711 commented 3 weeks ago

Operating System

windows10

Browser Version

chrome

Firebase SDK Version

1.7.2

Firebase SDK Product:

Auth

Describe your project's tooling

Angular 16 single page application

Describe the problem

I am trying to authenticate into firebase using keycloak as OIDC. I am using authorization code flow of the firebase configuration. Below is the code that I have written for the same.

Upon calling this block of code I'm getting following error "MISSING_OR_INVALID_NONCE : The nonce in ID Token does not match the SHA256 hash of the raw nonce in the request.". If anyone from the community knows, any guidance would be appreciated.

I have tried adding rawNonce field but it's giving the same error, also I tried disabling the NONCE field from the keycloak dashboard.

Steps and code to reproduce issue

const provider = new OAuthProvider('oidc.kc-dev');

const credential = provider.credential({
  idToken: id_token
  accessToken: access,
});

signInWithCredential(getAuth(), credential)
  .then((result: any) => {
    // Get the OAuth access token and ID Token
    const credential1 = OAuthProvider.credentialFromResult(result);
    console.log(credential1);
  })
  .catch((error: any) => {
    // Handle error.
  });