简体   繁体   English

Azure AD B2C 在尝试单击链接进行签名时抛出 404

[英]Azure AD B2C throwing a 404 when attempting to clicking the link to sign

I have an asp.netcore 3.1 web application that uses Azure AD B2C for authentication, this works perfectly when running the application locally.我有一个 asp.netcore 3.1 web 应用程序,它使用 Azure AD B2C 进行身份验证,这在本地运行应用程序时非常有效。 When the user clicks on the Sign In link the user is redirected to azure Ad B2C sign in/registration page.当用户点击登录链接时,用户将被重定向到 azure Ad B2C 登录/注册页面。 After user authenticates they are redirected back the local application.用户通过身份验证后,他们将被重定向回本地应用程序。

Here is the code configuration下面是代码配置

 public void ConfigureServices(IServiceCollection services)
        {
    services.AddAuthentication(AzureADB2CDefaults.AuthenticationScheme)
                   .AddAzureADB2C(options =>
                   {
                       Configuration.Bind("AzureAdB2C", options);
                   })
                   .AddCookie();

            services.Configure<OpenIdConnectOptions>(AzureADB2CDefaults.AuthenticationScheme, opt =>
             {
                 //Configuration.Bind("AzureAdB2C", opt);

                 opt.Authority = Configuration["OIDC:Authority"];
                 opt.RequireHttpsMetadata = true;
                 opt.GetClaimsFromUserInfoEndpoint = true;

                 opt.ClientId = Configuration["OIDC:ClientId"];
                 opt.ClientSecret = Configuration["OIDC:Secret"];
                 opt.ResponseType = "code";

                 opt.SaveTokens = true;
                 opt.AuthenticationMethod = OpenIdConnectRedirectBehavior.FormPost;

                 opt.Events = new OpenIdConnectEvents
                 {
                     OnUserInformationReceived = async ctx =>
                     {

                     },
                     OnTokenValidated =async  ctx =>
                     {
                         //Get user's immutable object id from claims that came from Azure AD
                         Guid userId = Guid.Empty;
                         if (ctx.HttpContext.User.Identity.IsAuthenticated)
                         {
                             if (!string.IsNullOrWhiteSpace(ctx.HttpContext.User.FindFirstValue("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name")))
                                 userId = Guid.Parse(ctx.HttpContext.User.FindFirstValue("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name"));

                             //Get EF context
                             var userRepo = ctx.HttpContext.RequestServices.GetRequiredService<IUserRepository>();

                             //Check is user a super admin
                             userRepo.RecordLogin(new Client.Models.EditModel.Account.RecordLoginEditModel()
                             {
                                 AttemptedAt = DateTimeOffset.UtcNow,
                                 UserId = userId,
                                 LoginResult = "Success",
                                 OnlineState = "Online",
                                 SStGAppId = "CustomerPortal"
                             });
                         }

                         //return Task.CompletedTask();
                     }
                 };
             });

...
}

public async void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            ...

            app.UseHttpsRedirection();
            app.UseStaticFiles();

            app.UseRouting();

            app.UseAuthentication();
            app.UseAuthorization();
            app.UseLogContextEnrichment();
            app.UseCorrelationEnrichment();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapRazorPages();
                endpoints.MapControllers();
            });
}

This is resulting 404 when clicking the sign in link on production site单击生产站点上的登录链接时会出现 404

在此处输入图像描述

As shown on the image above, the web app is running on an azure app service and being visited from the live domain, the site attempts to change to the azure AD b2c page, then instantly redirects back to the CustomDomain.com/signin-oidc which is the listed as the redirect uri in the Azure AD B2c Portal.如上图所示,web 应用程序运行在 azure 应用程序服务上,并从实时域访问该站点,该站点尝试更改为 azure AD b2c 页面,然后立即重定向回 CustomDomain.com/signin-oidc这是在 Azure AD B2c 门户中作为重定向 uri 列出的。

在此处输入图像描述

I am trying to figure out what the problem is.我想弄清楚问题是什么。 All the sites have SSL certificates too.所有站点也都有 SSL 个证书。

I finally figured out what the problem was.我终于弄清楚问题出在哪里了。 The redirect URI was for azure AD B2c was:重定向 URI 是 azure AD B2c 是:

I changed it to:我把它改成:

I also added我还添加了

This is a custom domain on my app service.这是我的应用程序服务上的自定义域。 When looking at the app custom domain it on the app service it is sstg-app.com.在应用服务上查看应用自定义域时,它是 sstg-app.com。

I hope this helps others.我希望这对其他人有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM