Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

React SPA - Unable to properly logout #1206

Open
ETFairfax opened this issue Apr 17, 2024 · 3 comments
Open

React SPA - Unable to properly logout #1206

ETFairfax opened this issue Apr 17, 2024 · 3 comments
Labels
Amazon Cognito question Further information is requested

Comments

@ETFairfax
Copy link

ETFairfax commented Apr 17, 2024

Hello,

I've a simple app with the copy/paste code from the installation instructions with some additions.

I am able to click Sign. Doing so redirects my to OIDC Sign In screen, I fill in credentials, then I am redirected back to my React SPA and my access token is available. All good so far👍

However, clicking Sign Out I am redirected to OP /logout. If I then navigate back to the React SPA, when I click Sign In I am automatically signed in without being asked for credentials. How is that so?

I've cleared all application storage and it still seems to know who I am? The only way I get to the login screen, is if I open an Incognito tab.

My Sign Out button has the following handler:

const handleSignOut = async () => {
    await auth.signoutRedirect({
      extraQueryParams: {
        client_id: oidcConfig.client_id,
        redirect_uri: 'http://localhost:4200',
        response_type: 'code'
      }
    });
    await auth.removeUser();
  };
const oidcConfig: AuthProviderProps = {
  authority: 'https://cognito-idp.region-xyz-1.amazonaws.com/my-pool-id',
  client_id: 'xyz',
  redirect_uri: 'http://localhost:4200', // Redirect URL must match cognitos App client > Hosted UI > Allowed callback URLs
  onSigninCallback,
  // https://github.com/authts/oidc-client-ts/blob/main/docs/index.md#provider-specific-settings
  // no revoke of "access token" (https://github.com/authts/oidc-client-ts/issues/262)
  revokeTokenTypes: ['refresh_token'],
  // no silent renew via "prompt=none" (https://github.com/authts/oidc-client-ts/issues/366)
  automaticSilentRenew: false
};

Any ideas?

Edit: Could this be the issue? https://stackoverflow.com/questions/49309928/cant-destroy-aws-cognito-session-from-within-react-application

@pamapa pamapa added question Further information is requested Amazon Cognito labels Apr 17, 2024
@pamapa
Copy link
Member

pamapa commented Apr 17, 2024

However, clicking Sign Out I am redirected to OP /logout. If I then navigate back to the React SPA, when I click Sign In I am automatically signed in without being asked for credentials. How is that so?

Is there a session cookie placed by cognito-idp?

@ETFairfax
Copy link
Author

ETFairfax commented Apr 17, 2024

However, clicking Sign Out I am redirected to OP /logout. If I then navigate back to the React SPA, when I click Sign In I am automatically signed in without being asked for credentials. How is that so?

Is there a session cookie placed by cognito-idp?

Looks like /oauth2/idpresponse does set a cognito cookie

...but how would that take effect if I clear all cookies (via dev tools)?

@ryanhsmfc
Copy link

@ETFairfax

i just came and using this library today, maybe late reply but this is what i find with aws cognito

maybe for anyone who find same problem

first i put this config as usual:

notes my region is sydney,

const oidcConfig: AuthProviderProps = {
  authority: "https://cognito-idp.ap-southeast-2.amazonaws.com/ap-southeast-2_xxxxxxx",
  client_id: "5nxxxxxxxxxxxxxxm",
  redirect_uri: "http://localhost:3000/login"
}

this is for logout function

export function useAuthSignoutRedirect() {
  const auth = useAuth()

  return () =>
    auth.signoutRedirect({
      // aws cognito extras
      extraQueryParams: {
        client_id,
        logout_uri: "http://localhost:3000/logout"
      },
    })
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Amazon Cognito question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants