![](/img/trans.png)
[英]/sign-in-oidc is returning 404 when sigining in using Azure AD B2C
[英]Azure AD B2C throwing a 404 when attempting to clicking the link to sign
我有一個 asp.netcore 3.1 web 應用程序,它使用 Azure AD B2C 進行身份驗證,這在本地運行應用程序時非常有效。 當用戶點擊登錄鏈接時,用戶將被重定向到 azure Ad B2C 登錄/注冊頁面。 用戶通過身份驗證后,他們將被重定向回本地應用程序。
下面是代碼配置
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();
});
}
單擊生產站點上的登錄鏈接時會出現 404
如上圖所示,web 應用程序運行在 azure 應用程序服務上,並從實時域訪問該站點,該站點嘗試更改為 azure AD b2c 頁面,然后立即重定向回 CustomDomain.com/signin-oidc這是在 Azure AD B2c 門戶中作為重定向 uri 列出的。
我想弄清楚問題是什么。 所有站點也都有 SSL 個證書。
我終於弄清楚問題出在哪里了。 重定向 URI 是 azure AD B2c 是:
我把它改成:
我還添加了
這是我的應用程序服務上的自定義域。 在應用服務上查看應用自定義域時,它是 sstg-app.com。
我希望這對其他人有幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.