首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >AzureAdB2C中间件必须提供'ClientId‘选项

AzureAdB2C中间件必须提供'ClientId‘选项
EN

Stack Overflow用户
提问于 2021-03-08 23:42:31
回答 1查看 717关注 0票数 0

我有一个angular应用程序,它能够通过azure b2c进行身份验证,但也有一个自定义的web api,但当添加.net核心web api的中间件时,我得到了“必须提供应用程序设置中的哪个ClientId ?这就像应用程序设置没有绑定一样。”

我已经在azure中配置了所有的api,作用域,赋予权限等。

我现在只使用本地帐户,所以我没有设置任何其他身份提供者,所以应该从web api使用clientid。我不确定我错过了什么

代码语言:javascript
复制
//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.

启动

代码语言:javascript
复制
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();
            });
        }
    }
}
EN

回答 1

Stack Overflow用户

发布于 2021-03-10 03:02:48

好吧,整个问题最终被证明是Kestrel。当我使用IIS Express时,一切都正常工作。不真实

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66532779

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档