Azure ADB2C signin-oidc 在 ASP.NET 核心 2 网络应用程序中失败

Azure ADB2C signin-oidc failing in ASP.NET Core 2 web app

希望有人能帮助我解决我在使用 Azure AD B2C 和 ASP.NET Core 2 Web 应用程序时遇到的问题。

问题出在 signin-oidc 路线上。

当我在本地 运行 时,一切正常,但当我将其推送到 Azure 时,该页面返回 400 错误,请参见下面的屏幕截图以获取更多信息:

这是 运行在本地的样子:

我正在为如何解决这个问题而苦恼。我已经搜索了 Web 应用程序中的日志和 Azure ADB2C 的审计日志,但似乎无法找到根本问题。

这是我的身份验证代码:

services.AddAuthentication(options =>
{
    options.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme;
    options.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
    options.DefaultChallengeScheme = CookieAuthenticationDefaults.AuthenticationScheme;
})
.AddCookie()
.AddOpenIdConnect("AzureADB2C", options =>
{
    options.Authority = Configuration.GetValue<string>("AzureADB2COptions:Authority");
    options.ClientId = Configuration.GetValue<string>("AzureADB2COptions:ClientId");
    options.ClientSecret = Configuration.GetValue<string>("AzureADB2COptions:ClientSecret");
    options.RequireHttpsMetadata = false;
    options.MetadataAddress = Configuration.GetValue<string>("AzureADB2COptions:MetadataAddress");

    options.ResponseType = OpenIdConnectResponseType.IdToken;

    options.Scope.Clear();
    options.Scope.Add("openid");

    options.CallbackPath = new PathString(
        Configuration.GetValue<string>("AzureADB2COptions:CallbackPath"));

    options.ClaimsIssuer = "AzureADB2C";

    options.TokenValidationParameters =
        new TokenValidationParameters
        {
            NameClaimType = "name"
        };

    options.Events = new OpenIdConnectEvents
    {
        OnAuthorizationCodeReceived = (context) =>
        {
            return Task.CompletedTask;
        },
        OnAuthenticationFailed = (context) =>
        {
            return Task.CompletedTask;
        },
        OnTokenResponseReceived = (context) =>
        {
            return Task.CompletedTask;
        },
        OnTokenValidated = async (context) =>
        {
            if (context.SecurityToken is JwtSecurityToken token)
            {
                if (context.Principal.Identity is ClaimsIdentity identity)
                {
                    ...
                }
            }
        }
    };
});

就像我说的,它在本地工作,而不是在 Azure 中。

如有任何帮助,我们将不胜感激!

我想通了这个问题,不好意思说这与Azure ADB2C 无关,还以为是signin-oidc 被炸掉了。

我连接了 AppInsights,特别是 Live Metrics Stream,并且能够找出问题...它是由拼写错误的 AppSetting 引起的。

感谢所有花一分钟时间看这个问题的人,而不是删除这个问题,

我就把它留在这里,也许可以避免其他人遇到一两个令人尴尬的问题。