Skip to content
Advertisement

Invalid token, state does not match – Auth0 Error Safari only

while using parseHash function in Auth0 library in safari I am getting error enter image description here

Same code is working fine in chrome. what can be possibly done to resolve this issue?

handleAuthentication = (onSuccessCallback, onErrorCallback) => {
    console.log('handle auth', this.authservice);
    this.authservice.parseHash((err, authResult) => {
      console.log('authresult inside', authResult, 'error', err);
      if (authResult && authResult.accessToken && authResult.idToken) {
        this.setSession(authResult, onSuccessCallback);
      } else if (err) {
        // onErrorCallback();
      }
    });
  };

Advertisement

Answer

After lots of research and article exploration, I finally found a solution to this issue. As auth0 is unable to access state and nonce parameters which are required for forwarding to check login details therefore we can manually add it for the authentication flow to work without any issue.

login = () => {
    this.authservice.authorize(
      {
        nonce: ${randomString},
        state: ${randomString},
      }
    );
  }

handleAuthentication = (onSuccessCallback, onErrorCallback) => {
  this.authservice.parseHash(
    {nonce: ${randomString}, state: ${randomString},
      (err, result) => {
        // some code
       }
     );
   };

Hope it works for you too!!

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement