Azure active directory 无法从以下位置获取配置:';https://login.microsoftonline.com/
我将msal用于angular 8,将.NET core 2.2用于webapi。我从angular应用程序创建令牌,并希望验证webapi。 我已经在Azure portal中注册了我的两个应用程序(angular和localhost webapi),还公开了api。 以下是我的app.module.ts文件内容:Azure active directory 无法从以下位置获取配置:';https://login.microsoftonline.com/,azure-active-directory,asp.net-core-webapi,angular8,msal,Azure Active Directory,Asp.net Core Webapi,Angular8,Msal,我将msal用于angular 8,将.NET core 2.2用于webapi。我从angular应用程序创建令牌,并希望验证webapi。 我已经在Azure portal中注册了我的两个应用程序(angular和localhost webapi),还公开了api。 以下是我的app.module.ts文件内容: let msalConfig: MsalConfig; export function initializeApp(appConfig: AppConfig) { const
let msalConfig: MsalConfig;
export function initializeApp(appConfig: AppConfig) {
const promise = appConfig.loadAppConfig().pipe(tap((settings: IAppConfig) => {
const protectedResourceMap:[string, string[]][]=
[
['http://localhost:7308/api/values',['api://{azure-web-api-app-clientID}/values']],
];
msalConfig = {
authority: 'https://login.microsoftonline.com/{azure-tenantId}',
clientID: 'azure-angular-api-app-clientID',
protectedResourceMap: protectedResourceMap,
validateAuthority: true,
isAngular:true,
piiLoggingEnabled:true,
cacheLocation : "localStorage",
redirectUri: "http://localhost:8081/",
storeAuthStateInCookie: true
};
})).toPromise();
return () => promise;
}
export function msalConfigFactory() {
return msalConfig;
}
下面是app.module.ts中的提供者
providers: [
ProductService,
{
provide: APP_INITIALIZER,
useFactory: initializeApp,
deps: [AppConfig],
multi: true
},
MsalService,
{
provide: MSAL_CONFIG,
useFactory: msalConfigFactory
},
{
provide: HTTP_INTERCEPTORS,
useClass: MsalInterceptor,
multi: true
}
]
对于Asp.net core 2.2 webapi startup.cs文件
public void ConfigureServices(IServiceCollection services)
{
services.AddCors(options =>
{
options.AddPolicy("EnableCors", builder =>
{
builder.WithOrigins("http://localhost:8081").AllowAnyHeader().AllowAnyMethod();
});
});
services.AddAuthentication(sharedOptions =>
{
sharedOptions.DefaultScheme = AzureADDefaults.BearerAuthenticationScheme;
})
.AddAzureADBearer(options => Configuration.Bind("AzureActiveDirectory", options));
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
IdentityModelEventSource.ShowPII = true;
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
app.UseDeveloperExceptionPage();
app.UseCors("EnableCors");
app.UseAuthentication();
app.UseStaticFiles();
app.UseMvc();
}
在appsettings.json中
"AzureActiveDirectory": {
"Instance": "https://login.microsoftonline.com/",
"Domain": "{my-domain}.onmicrosoft.com",
"TenantId": "{azure-web-app-api-tenantid}",
"ClientId": "azure-web-api-app-clientID"
}
当我尝试调用这个api时,我得到了500个错误。它甚至不指向api(/api/values)
准确的误差是
IDX20803:无法从以下位置获取配置:{my tennanti}/.well-known/openid configuration'听起来好像有什么东西阻止了前端获取元数据文档的请求。你有防火墙阻止它吗?你有互联网连接吗?如果直接在浏览器中输入该URL会发生什么?是否对此问题进行了任何更新?听起来好像有什么东西阻止了前端获取元数据文档的请求。你有防火墙阻止它吗?你有互联网连接吗?如果直接在浏览器中输入该URL会发生什么情况?此问题有任何更新吗?