我是Azure Active Directory身份验证概念的初学者。
我试图在现有的“角Web核心”应用程序(Multi-tenant).中实现Azure Active身份验证
我已经按照Microsoft Azure Active的指示实现了一切。
但是,在调用"AuthenticationResult“方法之后,"loginRedirect”将在应用程序的角客户端以NULL的形式返回。(这里没有调用特定于应用程序的Web调用)。
问题:单击“登录”按钮的应用程序登录页=>导航到Microsoft Azure Login Page =>,提供凭据,用户将重新定向回应用程序登录页,而不是注册的RedirectURI
提供以下应用程序的结构:
authService => instance of MsalService.
msalBroadCastService => instance of MsalBroadcastService.
msalGuardConfig => instance of MsalGuardConfiguration.
isUserLoggedIn: boolean = false;ngOnInit(): void {
this.authService.handleRedirectObservable().subscribe({
next: (result: AuthenticationResult) => { // few console log code snippet },
error: (error) => console.log(error)
});
}ngOnInit() {
// have tried the following with "handleRedirectPromise" also, but it didn't work.
this.authService.handleRedirectObservable().subscribe({
next: (result: AuthenticationResult) => {
this.msalBroadCastService.inProgress$
.pipe(
filter((status: InteractionStatus) => status === InteractionStatus.None),
takeUntil(this.destroy$)
)
.subscribe((x) => {
// the component "redirect-path" is the redirectURI mentioned in the application configuration file and also in the Azure Active Directory redirectURI section.
if (result)
this.router.navigate(['redirect-path']);
})
},
error: (errorMsg) => {
debugger;
console.log(errorMsg)
}
});
....
....
// Existing logic to load the application "Login" page.
}
onLogin(){
this.authService.instance.handleRedirectPromise()
.then((tokenResponse) => {
if (!tokenResponse) {
this.isUserLoggedIn = this.authService.instance.getAllAccounts().length == 0;
if (this.isUserLoggedIn) {
this.authService.loginRedirect({ ...this.msalGuardConfig.authRequest } as RedirectRequest);
}
}
});
}MsalModule.forRoot(new PublicClientApplication(
{
auth: {
clientId: '<Client ID>',
redirectUri: 'http://localhost:4200/#/redirect-path',
authority: 'https://login.microsoftonline.com/organizations'
// authority: 'https://login.microsoftonline.com/common' // Tried this also, but didn't work.
},
cache: {
cacheLocation: 'localStorage',
storeAuthStateInCookie: isIE
},
system: {
loggerOptions: {
loggerCallback: (level: LogLevel, message: string, containsPii: boolean): void => {
if (containsPii) {
return;
}
switch (level) {
case LogLevel.Error:
console.error(message);
return;
case LogLevel.Info:
console.info(message);
return;
case LogLevel.Verbose:
console.debug(message);
return;
case LogLevel.Warning:
console.warn(message);
return;
}
},
piiLoggingEnabled: false
},
windowHashTimeout: 60000,
iframeHashTimeout: 6000,
loadFrameTimeout: 0,
asyncPopups: false
}
}
),
{
interactionType: InteractionType.Redirect,
authRequest: {
scopes: ['user.read']
}
},
{
interactionType: InteractionType.Redirect,
protectedResourceMap: new Map(
[
['https://graph.microsoft.com/v1.0/me', ['user.read']]
]
)
}
)
providers: [
{
provide: HTTP_INTERCEPTORS,
useClass: MsalInterceptor,
multi: true
}, MsalGuard
]const routes: Routes = [
{ path: '', component: LoginComponent, pathMatch: 'full' },
// { path: '', component: LoginComponent, pathMatch: 'full', canActivate: [MsalGuard] },
{ path: 'redirect-path', component: RedirectPathComponent, pathMatch: 'full' },
// { path: 'redirect-path', component: RedirectPathComponent, pathMatch: 'full', canActivate: [MsalGuard] },
]<body>
<app-root></app-root>
<app-redirect></app-redirect>
</body>如果需要任何其他配置相关信息,请让我知道(我可能漏掉了)。
您的指导将不胜感激。
发布于 2022-06-10 11:13:27
嗨,Debasmita,您不应该在初始化LoginComponent时清除存储在本地存储中的所有数据。这是因为PublicClientApplication被配置为使用本地存储(cacheLocation:'localStorage')
https://stackoverflow.com/questions/72539838
复制相似问题