syncweek-react-aad / react-aad

A React wrapper for Azure AD using the Microsoft Authentication Library (MSAL). The easiest way to integrate AzureAD with your React for authentication.
MIT License
344 stars 94 forks source link

Redirect the user to the page he is trying to access by having it in the browser memory #288

Open sneha-boopal opened 3 years ago

sneha-boopal commented 3 years ago

Requirement is that after a user logs in via Azure AD (or any identity provider really), they should be redirected to the page they tried to access. Meaning a flow like this:

User tries to access http://localhost:3000/products App redirects them to log in with Azure AD 3)User is redirected back to the application, and should now see the product list instead of getting redirected to index page(http://localhost/products). I tried by adding http://localhost:3000/products in redirectUri but still it is getting redirected to http://localhost:3000. Is it achievable using msal and please provide if there are any sample apps

jasonnutter commented 3 years ago

I'm not sure about via react-aad-msal APIs, but MSAL supports passing the redirectStartPage parameter, which tells MSAL where to navigate after coming back from the redirect. Note, this requires auth.navigateToLoginRequestUrl to be enabled.

This is how we do it in MSAL Angular: https://github.com/AzureAD/microsoft-authentication-library-for-js/blob/msal-angular-v1/lib/msal-angular/src/msal-guard.service.ts#L75