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

Access Token not come #252

Open Anand-rana opened 4 years ago

Anand-rana commented 4 years ago

Library versions

react-aad-msal: 2.3.5 msal: 1.3.2

Describe the bug I've attempted to replace ADAL with MSAL. The first time the user accesses the app it authenticates correctly, but I am getting into a situation where our app goes into a redirect loop after a period of time. I presume this is when the token expires (1 hour by default, I believe). This happens sometimes when the app is idle after an hour, which is why I think it may be to do with the way a new token is obtained as well as when I refresh the browser window.

AuthProvider.ts

import { MsalAuthProvider, LoginType } from "react-aad-msal";

export const authProvider = new MsalAuthProvider( { auth: { authority: 'https://MxHHStaging.b2clogin.com/MxHHStaging.onmicrosoft.com/B2C_1_SUSI', clientId: '', postLogoutRedirectUri: window.location.origin, redirectUri: window.location.origin, validateAuthority: false, navigateToLoginRequestUrl: false, },

cache: {
  cacheLocation: "localStorage",
  storeAuthStateInCookie: true
}

}, { scopes: ['https://MxHHStaging.onmicrosoft.com/Web/userimpersonation'], }, { loginType: LoginType.Redirect, tokenRefreshUri: window.location.origin + '/auth.html', } );

const token = await authProvider.getAccessToken()

this will provide error redirect to home screen.

brunoandradebr commented 4 years ago

You are supposed to change oauth2AllowImplicitFlow to true. It's configuration is located at :

https://portal.azure.com/#blade/Microsoft_AAD_RegisteredApps/ApplicationMenuBlade/Authentication/appId/YOUR-APP-ID

And just check Access token then authProvider.getAccessToken() will return a valid token.