代码之家  ›  专栏  ›  技术社区  ›  Charles Boyung

返回主站点时B2C编辑配置文件自定义策略问题

  •  0
  • Charles Boyung  · 技术社区  · 3 年前

    我有一个.Net 4.6.2 web应用程序,正在设置为使用AAD B2C。它有一个OwinStartup类,该类具有以下内容:

                app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions
                {
                    MetadataAddress = String.Format($"{b2cAadInstance}", b2cTenantName,"v2.0/.well-known/openid-configuration?p=", b2cSignInPolicy,""),
                    ClientId = b2cClientId,
                    RedirectUri = b2cRedirectUri,
                    PostLogoutRedirectUri = b2cRedirectUri,
                    SignInAsAuthenticationType = "cookie",
                    // authorize scope
                    Scope = "openid offline_access",
                    RequireHttpsMetadata = false,
                    UseTokenLifetime = false,
                    RedeemCode = true,
                    SaveTokens = true,
                    ResponseType = "code",
                    ResponseMode = "query",
                    // Specify the callbacks for each type of notifications
                    Notifications = new OpenIdConnectAuthenticationNotifications
                    {
                        RedirectToIdentityProvider = OnRedirectToIdentityProvider,
                        AuthorizationCodeReceived = OnAuthorizationCodeReceived,
                        AuthenticationFailed = OnAuthenticationFailed,
                    }
    
                });
    

    这一切在登录时都可以正常工作。用户经过身份验证并重定向到主站点。但是,代码设置为将它们发送回自定义策略以编辑其配置文件。它使用以下代码在OnRedirectToIdentityProvider中执行此操作:

                if (!string.IsNullOrEmpty(policy) && !policy.Equals(b2cSignInPolicy, StringComparison.OrdinalIgnoreCase))
                {
                    notification.ProtocolMessage.IssuerAddress = notification.ProtocolMessage.IssuerAddress.ToLower().Replace(b2cSignInPolicy.ToLower(), policy.ToLower());
                }
    

    这用于将用户发送到自定义编辑配置文件策略。然而,问题是当他们完成编辑他们的个人资料和B2C返回他们的网站。这个 OnAuthorizationCodeReceived 方法,但紧接着, OnAuthenticationFailed 也被调用,B2C提供以下错误消息:

    OpenIdConnectMessage。错误不为null,表示有错误。错误:“无效的授权”。错误描述(可能为空):“AADB2C90088:尚未为此终结点颁发提供的授权。实际值:B2C_1A_签名和预期值:B2C_1A_ProfileEdit

    B2C_1A_ProfileEdit policy 在上面的代码中,这是将用户发送到配置文件编辑屏幕的代码。

    我已经看到了一些代码示例,它们似乎应该处理这种情况,但它们都在.Net Core中,不幸的是,这与4.6.2如何处理B2C不兼容。

    0 回复  |  直到 3 年前