处理不完整或出错的远程注销

时间:2018-11-13 21:34:39

标签: c# asp.net asp.net-core-2.0 identityserver4

我刚刚更新了我的应用程序(使用身份服务器4)以使用.net core 2.1框架。生产实例使用.net core 1.1,并且那里没有这个问题。该应用程序支持多个开放ID提供程序,其中之一就是B2C。与其他目录不同,注销过程无法完全完成。在.net core 1.1中,注销将以身份服务器注销页面结束。但是使用.net core 2.1,我看到一个空白页。身份服务器端命中的最后一个URL是https://<id-server>/signout-callback-oidc?state=<state>。我怀疑状态已损坏?不幸的是,只有在将其部署到应用程序服务后,该问题才会发生,在本地我没有任何问题。

关于日志-一旦到达结束会话终点(EndSessionEndpoint),日志记录就会结束。返回EndSessionResult后,就不再进行日志记录。因此,如果我查看日志,则表示成功。

我尝试了很多事情,例如在B2C注册接受的答复URL列表中指定已注销的回调URL,自定义状态数据格式怀疑是冗长的URL。但是没有任何效果。这些用户的索赔数量也更少-约为7/8。我也尝试过使用OpenIdConnectEvents.OnRemoteSignoutOpenIdConnectEvents.OnSignedOutCallbackRedirect,但似乎并没有调用这些回调。

身份服务器日志

[02:16:36 Information] IdentityServer4.Validation.EndSessionRequestValidator
End session request validation success
{
  "ClientId": "<id>",
  "ClientName": "<nmame>",
  "SubjectId": "<sub-id>",
  "PostLogOutUri": "https://<app>/signout-callback-oidc",
  "State": "<state>",
  "Raw": {
    "post_logout_redirect_uri": "https://<app>/signout-callback-oidc",
    "id_token_hint": "<token-hint>",
    "state": "<state>",
    "x-client-SKU": "ID_NET",
    "x-client-ver": "2.1.4.0"
  }
}

[02:16:36 Debug] IdentityServer4.Endpoints.EndSessionEndpoint
Success validating end session request from <app-client-id>

[02:16:37 Information] Microsoft.AspNetCore.Authentication.Cookies.CookieAuthenticationHandler
AuthenticationScheme: Identity.Application signed out.

[02:16:37 Information] Microsoft.AspNetCore.Authentication.Cookies.CookieAuthenticationHandler
AuthenticationScheme: Identity.External signed out.

[02:16:38 Information] Microsoft.AspNetCore.Authentication.Cookies.CookieAuthenticationHandler
AuthenticationScheme: Identity.TwoFactorUserId signed out.

[02:16:38 Information] Microsoft.AspNetCore.Authentication.OpenIdConnect.OpenIdConnectHandler
AuthenticationScheme: OpenIdConnect signed out.

遍历的网址顺序

.Net核心2.1(停在signout-callback-oidc?state = 带有空白页的地方)

.Net核心1.1(成功)

我的问题

  • 有什么想法吗?
  • 如果退出未完成 完全可以,我有什么方法可以恢复并重定向到预定义的 页面?

打开ID设置

services.AddOpenIdConnect(adSettingsB2c.SchemeName, adSettingsB2c.DisplayName, options =>
{
    options.SignInScheme = IdentityServerConstants.ExternalCookieAuthenticationScheme;
    options.SignOutScheme = IdentityServerConstants.SignoutScheme;
    options.Authority = $"{adSettingsB2c.AADInstance}/{adSettingsB2c.Tenant}/B2C_1_{adSettingsB2c.SignInPolicyId}/v2.0";
    options.CallbackPath = adSettingsB2c.CallbackPath;
    options.ClientId = adSettingsB2c.ClientId;
    options.ResponseType = OpenIdConnectResponseType.IdToken;
    options.SaveTokens = true;
    options.TokenValidationParameters = new TokenValidationParameters
    {
        ValidateIssuer = true
    };
    options.Events = new OpenIdConnectEvents
    {
        OnRedirectToIdentityProvider = r =>
        {
        var defaultPolicy = adSettingsB2c.SignInPolicyId;
        if (r.Properties.Items.TryGetValue("Policy", out var policy) &&
            !policy.Equals(defaultPolicy))
        {
            r.ProtocolMessage.Scope = OpenIdConnectScope.OpenIdProfile;
            r.ProtocolMessage.ResponseType = OpenIdConnectResponseType.IdToken;
            r.ProtocolMessage.IssuerAddress = r.ProtocolMessage.IssuerAddress.ToLower().Replace(defaultPolicy.ToLower(), policy.ToLower());
            r.Properties.Items.Remove("Policy");
        }
        if (r.Properties.Items.ContainsKey("email_address"))
        {
            r.ProtocolMessage.SetParameter("login_hint", r.Properties.Items["email_address"]);
        }
        return Task.FromResult(0);
        },
        OnRemoteFailure = r => { // ... }
    };
    })

我也已在身份服务器存储库中发布了此问题,以防万一您想在此添加它! -https://github.com/IdentityServer/IdentityServer4/issues/2794

1 个答案:

答案 0 :(得分:0)

问题是,当使用const data = ['dogs', 'cats']; localStorage.myData = JSON.stringify(data); // Time to retrieve it back from localStorage displayMyData(JSON.parse(localStorage.myData)); 方法设置选项时,我没有为引起此问题的每个开放ID提供程序设置AddOpenIdConnect。完成后,注销将按预期开始工作!