【发布时间】:2020-02-19 12:49:41
【问题描述】:
我正在尝试创建一个 PoC 应用程序集,带有 Angular(其他或变体前端)的 WebApi,使用 Azure AD 对我的联合用户进行身份验证。
我的后端工作正常,身份验证/MFA 按预期工作,并显示登录提示。
我有 Angular 应用程序的 Microsoft 示例,但我正在努力实现所述应用程序,我应该使用 MSAL 在前端获取令牌,并让后端接受所述令牌并作为联合身份验证用户?
这是我在示例中的app.module.ts 代码,其中
export const protectedResourceMap:[string, string[]][]=[ ['https://localhost:5001/',['api://--------------/access_as_user']] , ['https://graph.microsoft.com/v1.0/me', ['user.read']] ];
const isIE = window.navigator.userAgent.indexOf("MSIE ") > -1 || window.navigator.userAgent.indexOf("Trident/") > -1;
@NgModule({
declarations: [
AppComponent, HomeComponent, ProductComponent, ErrorComponent, ProductDetailComponent, TodoListComponent, UserDataComponent
],
imports: [
BrowserModule,
FormsModule,
HttpClientModule,
RouterModule.forRoot(appRoutes,{useHash:true}) ,
MsalModule.forRoot({
clientID: '-----------',
authority: "https://login.microsoftonline.com/common/",
validateAuthority: true,
redirectUri: "http://localhost:4200/",
cacheLocation : "localStorage",
storeAuthStateInCookie: isIE, // set to true for IE 11
postLogoutRedirectUri: "http://localhost:4200/",
navigateToLoginRequestUrl: true,
popUp: !isIE,
consentScopes: [ "user.read", "openid", "profile", "api://------------/access_as_user"],
unprotectedResources: ["https://www.microsoft.com/en-us/"],
protectedResourceMap: protectedResourceMap,
logger: loggerCallback,
correlationId: '1234',
piiLoggingEnabled: true
}
),
],
providers: [ProductService, TodoListService, HttpServiceHelper,
{provide: HTTP_INTERCEPTORS, useClass: MsalInterceptor, multi: true}
],
bootstrap: [AppComponent]
})
【问题讨论】:
标签: angular asp.net-core azure-active-directory