I am currently starting with Angular and MSAL and I cannot figure out how to achieve the following:
- When the user access the WebApp, the Microsoft Login should appear (via Azure AD)
- After successful authentication, the webapp appears
- When the user clicks on Logout, the user should be logged out
- After the Logout, he should go back to step 1., so he should see the Microsoft Login again
This is what I have in my app.module.ts:
MsalModule.forRoot({
auth: {
clientId: '...', // This is your client ID
authority: '...',
// redirectUri: 'https://localhost:5001',
postLogoutRedirectUri: '**<--THIS MAYBE? BUT WHAT URL DO I PUT HERE TO COME BACK TO THE MICROSOFT LOGIN PAGE??**'
},
cache: {
cacheLocation: 'localStorage',
storeAuthStateInCookie: isIE, // Set to true for Internet Explorer 11
},
}, {
popUp: false,
consentScopes: [
'user.read',
'openid',
'profile',
],
unprotectedResources: [],
protectedResourceMap: [
// ['https://graph.microsoft.com/v1.0/me', ['user.read']]
],
extraQueryParameters: {}
})
],...
And here is my app-routing.module.ts:
const routes: Routes = [
{
path: '', canActivate: [MsalGuard], children: [
{path: '', component: HomeComponent},
{path: 'home', component: HomeComponent},
{path: 'tools', component: ToolsComponent}
]
}
];
The issue with the solution that I have now is: When I logout it will go to the WebApp again and then redirect to the MS login page. But I want him to go directly to the MS login page, so that the user does not see anything of the webapp anymore (after logout).
What I really need to prevent is, that the user can see anything of the webapp if he is not logged in. So I do not want to redirect him to a component (because then he sees the content again).