【发布时间】:2019-09-16 19:33:30
【问题描述】:
我尝试集成 Azure Active Directory 和 Asp.net CORE 2.2。
public void ConfigureServices(IServiceCollection services)
{
services.AddAuthentication(AzureADDefaults.BearerAuthenticationScheme)
.AddAzureADBearer(options => Configuration.Bind("AzureAd", options));
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseAuthentication();
app.UseMvc();
}
Appsettings.json
{"AzureAd": {
"Instance": "https://login.microsoftonline.com/",
"Domain": "xxxxx.onmicrosoft.com",
"TenantId": "xxxxxx",
"ClientId": "xxxx" } },"AllowedHosts": "*"}
结果: 错误:信息:Microsoft.AspNetCore.Authorization.DefaultAuthorizationService[2] 授权失败。
拜托,我找到了任何解决此问题的方法。
非常感谢
【问题讨论】:
-
我不知道这是否是您的情况,但如果您尝试使用 MS Graph 的令牌进行身份验证,它将无法正常工作。您需要为自己的 Web API 颁发令牌,而不是重复使用来自其他资源的令牌。
标签: azure asp.net-core azure-active-directory