从 Angular 9 个应用程序向 Azure AD 进行身份验证
Authenticate to Azure AD from Angular 9 Application
正在尝试从我的 Angular 应用程序使用 Azure AD 进行身份验证。由于网络上有太多过时的示例,因此很难理解如何去做。我一直在关注 github 上的最新文档,但在访问该应用程序时我一直收到此错误:
ClientConfigurationError: No redirect callbacks have been set. Please call handleRedirectCallback() with the appropriate function arguments before continuing
我应该怎么做才能让它发挥作用?
app-routing.module.ts
const routes: Routes = [
{ path: '', component: AppComponent, canActivate: [MsalGuard] },
{ path: 'auth-callback', component: DashboardComponent }
];
app.module.ts
const config = {
auth: {
clientId: 'my-client-id',
//popUp: true,
consentScopes: ['https://graph.microsoft.com/User.ReadWrite'],
redirectUri: 'http://localhost:4200/auth-callback',
}
};
@NgModule({
declarations: [
AppComponent,
DashboardComponent
],
imports: [
MsalModule.forRoot(config),
BrowserModule,
AppRoutingModule
],
providers: [
{
provide: HTTP_INTERCEPTORS,
useClass: MsalInterceptor,
multi: true
}
]
,
bootstrap: [AppComponent]
})
export class AppModule {
constructor() {
const myMSALObj = new UserAgentApplication(config);
function authCallback(error, response) { }
myMSALObj.handleRedirectCallback(authCallback);
}
您需要添加回调,即使它什么都不做。
您可以将其添加到模块构造函数中。
@NgModule({ ... })
export class AppModule {
constructor(msalService: MsalService) {
msalService.handleRedirectCallback(_ => { });
}
}
我不久前创建了一个博客 post 正是关于这个!
Angular 9 破坏了我的身份验证流程,因此必须解决问题。
你可以在那里查看完整的代码以及你应该注意的所有细节。
https://www.pshul.com/2020/03/29/authenticate-your-angular-9-to-azure-ad-using-msal/
正在尝试从我的 Angular 应用程序使用 Azure AD 进行身份验证。由于网络上有太多过时的示例,因此很难理解如何去做。我一直在关注 github 上的最新文档,但在访问该应用程序时我一直收到此错误:
ClientConfigurationError: No redirect callbacks have been set. Please call handleRedirectCallback() with the appropriate function arguments before continuing
我应该怎么做才能让它发挥作用?
app-routing.module.ts
const routes: Routes = [
{ path: '', component: AppComponent, canActivate: [MsalGuard] },
{ path: 'auth-callback', component: DashboardComponent }
];
app.module.ts
const config = {
auth: {
clientId: 'my-client-id',
//popUp: true,
consentScopes: ['https://graph.microsoft.com/User.ReadWrite'],
redirectUri: 'http://localhost:4200/auth-callback',
}
};
@NgModule({
declarations: [
AppComponent,
DashboardComponent
],
imports: [
MsalModule.forRoot(config),
BrowserModule,
AppRoutingModule
],
providers: [
{
provide: HTTP_INTERCEPTORS,
useClass: MsalInterceptor,
multi: true
}
]
,
bootstrap: [AppComponent]
})
export class AppModule {
constructor() {
const myMSALObj = new UserAgentApplication(config);
function authCallback(error, response) { }
myMSALObj.handleRedirectCallback(authCallback);
}
您需要添加回调,即使它什么都不做。 您可以将其添加到模块构造函数中。
@NgModule({ ... })
export class AppModule {
constructor(msalService: MsalService) {
msalService.handleRedirectCallback(_ => { });
}
}
我不久前创建了一个博客 post 正是关于这个! Angular 9 破坏了我的身份验证流程,因此必须解决问题。
你可以在那里查看完整的代码以及你应该注意的所有细节。 https://www.pshul.com/2020/03/29/authenticate-your-angular-9-to-azure-ad-using-msal/