question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Credentials immediately removed from localstorage after successful login with Hosted UI

See original GitHub issue

Do you want to request a feature or report a bug?

Bug

What is the current behavior?

Setup:

  • Cognito User Pool with federated users from azuread.
  • Simpl React app using withOAuth and Authenticator

With the following configuration:

Amplify.configure({
  API: {
...
  Auth: {
    region: 'eu-west-1',
    userPoolId: 'eu-west-POOL_ID',
    userPoolWebClientId: 'ClientID',
    oauth: {
      domain: 'blablabla.auth.eu-west-1.amazoncognito.com',
      scope : ['email', 'profile', 'openid'], 
      redirectSignIn : 'http://localhost:3000', 
      redirectSignOut : 'http://localhost:3000',
      responseType: 'token',
    },
  }
});
The login flow goes as follow:

Call OAuthSignIn() ➡️ Redirected to Cognito login page ➡️ Select the provider ➡️ Redirected to the provider Login Page ➡️ Login with my credentials ➡️ Redirected to http://localhost:3000/#access_token=ACCES_TOKEN=ID_TOKEN&token_type=Bearer&expires_in=3600

The Problem

When redirected with a working token (I tested it against my API) the SDK clear() the credentials in localstorage and redirect to http://localhost:3000.

The weird thing

If I remove the userPoolId from configuration and Call OAuthSignIn() again the credentials are not erased anymore however the Authenticator doesn’t log me in since userPoolId is not in the configuration anymore.

The other weird thing

If I put userPoolId back in the configuration with a filled localstorage I’m logged in.

What is the expected behavior?

SDK Should not signOut after successful OAuth login.

Which versions of Amplify, and which browser / OS are affected by this issue? Did this work in previous versions?

  • "aws-amplify": "^1.0.6"
  • "aws-amplify-react": "^1.0.6"

Issues #392, #1395, #1426 report similar issues related to hosted UI authentication and OAuth

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
powerful23commented, Sep 5, 2018

@theGlenn the bug has been confirmed, will work on to fix it.

1reaction
powerful23commented, Nov 6, 2018

@pmd30011991 hey we just merged a fix for this issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

javascript - Cognito hosted UI
This approach sends the user to cognito UI in tab 2, there the user makes the login process, if it is using google...
Read more >
Setting state using cookies with Puppeteer and Playwright
After a successful login, our saved cookies file will look something like this: [ { "name": "dotcom_user" ...
Read more >
The Complete Guide to React User Authentication with Auth0
The focus of this tutorial is to help developers learn how to secure a React application by implementing user authentication.
Read more >
How To Add Login Authentication to React Applications
This tutorial will focus on storing tokens in localStorage and sessionStorage . By the end of this tutorial, you'll be able to add ......
Read more >
Handling user authentication with Redux Toolkit
Our Express server, hosted on localhost:5000 , currently has ... It then returns a JWT after successful authentication or an error message.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found