marmelab / ra-auth-cognito

An auth provider for react-admin which handles authentication with AWS Cognito.
MIT License
9 stars 6 forks source link

Incorrect redirection on session expiration with Cognito/Google #3

Closed stripethree closed 1 year ago

stripethree commented 1 year ago

When a session expires, ra-auth-cognito does not appear to correctly redirect a user to the Cognito hosted UI.

In this state, this is what appears to happen, in chronological order:

If the {loginPage} attribute on <Admin> is set to Login (from this library), the user is forwarded to the Login view. This is not useful since username/password is not enabled. There appears to be no way to return to the Cognito Hosted UI login page without manually updating the URL in the location bar. Clearing browser data, navigating back to the applications root URL, etc. all lead to this scenario.

Screen Shot 2023-03-02 at 4 21 50 PM

If the {loginPage} attribute on <Admin> is set to false, which makes sense given the information in #2, the screen is stuck on a loading view:

Screen Shot 2023-03-02 at 4 22 00 PM

Making the following change in authProvider.ts checkAuth function resolves the issue in my testing:

        user.getSession((err, session) => {
          if (err) {
            console.log(err);
            // log the error?
+            return redirectToOAuthIfNeeded(new HttpError('No user', 401));
-            return reject(err);
          }

Changing this in getPermissions is not possible without larger changes, given where the redirectToOAuthIfNeeded is currently defined.

More information on the configuration of the application I am developing and how I am testing

Authentication flow session duration 3 minutes

Refresh token expiration 60 minutes

Access token expiration 5 minutes

ID token expiration 5 minutes

- Relevant package versions in the project:
"amazon-cognito-identity-js": "^6.1.2",
"ra-auth-cognito": "^1.0.0",
"ra-core": "4.7.2",
"ra-data-simple-rest": "4.8.1",
"react": "^18.2.0",
"react-admin": "4.7.1",
"react-dom": "^18.2.0",
"react-scripts": "5.0.1",


Please let me know if I can provide any more details that would help.
djhi commented 1 year ago

Thanks for the detailed report and the fix. I was able to reproduce it and fix it

julienV commented 1 year ago

Hi, I still have this exact same issue with 1.0.1...

julienV commented 1 year ago

please can you make a new release with the fix... it's in fact not in 1.0.1 image