我有一个angular应用程序,它能够通过azure b2c进行身份验证,但也有一个自定义的web api,但当添加.net核心web api的中间件时,我得到了“必须提供应用程序设置中的哪个ClientId ?这就像应用程序设置没有绑定一样。”
我已经在azure中配置了所有的api,作用域,赋予权限等。
我现在只使用本地帐户,所以我没有设置任何其他身份提供者,所以应该从web api使用clientid。我不确定我错过了什么
//tried this
services.AddMicrosoftIdentityWebApiAuthentication(Configuration, "AzureAdB2C");
//this as well
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddMicrosoftIdentityWebApi(Configuration.GetSection("AzureAdB2C"));
{
"AzureAdB2C": {
"Instance": "https://{domain}.b2clogin.com/",
"ClientId": "11111111-1111-1111-1111-111111111111",
"Domain": "{domain}.onmicrosoft.com",
"SignUpSignInPolicyId": "b2c_1_SignupSign"
},
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*"
}
Request starting HTTP/1.1 GET http://localhost:5000/weatherforecast
fail: Microsoft.AspNetCore.Server.Kestrel[13]
Connection id "0HM729054ALE1", Request id "0HM729054ALE1:00000001": An unhandled exception was thrown by the application.
Microsoft.Extensions.Options.OptionsValidationException: IDW10106: The 'ClientId' option must be provided.启动
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Identity.Web;
namespace WepApi1
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
//services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
// .AddMicrosoftIdentityWebApi(Configuration.GetSection("AzureAdB2C"));
services.AddMicrosoftIdentityWebApiAuthentication(Configuration, "AzureAdB2C");
services.AddAuthorization();
services.AddControllers();
services.AddCors(o => o.AddPolicy("CorsPolicy", builder =>
{
builder.WithOrigins("http://localhost:4200")
.AllowAnyMethod()
.AllowAnyHeader()
.AllowCredentials()
.SetIsOriginAllowed((host) => true);
}));
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
app.UseCors("CorsPolicy");
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
}
}
}发布于 2021-03-10 03:02:48
好吧,整个问题最终被证明是Kestrel。当我使用IIS Express时,一切都正常工作。不真实
https://stackoverflow.com/questions/66532779
复制相似问题