简体   繁体   English

IdentityServer 显示 Android Native App 的空白 PostLogoutRedirectUri

[英]IdentityServer shows blank PostLogoutRedirectUri for Android Native App

I have created an OAuth Server using IdentityServer4 and.Net Core Signin Manager.我使用 IdentityServer4 和 .Net Core Signin Manager 创建了一个 OAuth 服务器。 The Login works great and returns to my app.登录效果很好并返回到我的应用程序。 The Logout doesn't seem to know who is logging out.注销似乎不知道谁在注销。 The Logout Razor Page code is as follows:注销Razor页面代码如下:

   public async Task<IActionResult> OnGet(string logoutId)
    {

        var logout = await _interaction.GetLogoutContextAsync(logoutId);

        PostLogoutRedirectUri = logout?.PostLogoutRedirectUri;
        AutomaticRedirectAfterSignOut = (PostLogoutRedirectUri != null);
        ClientName = string.IsNullOrEmpty(logout?.ClientName) ? logout?.ClientId : logout?.ClientName;
        SignOutIframeUrl = logout?.SignOutIFrameUrl;
        LogoutId = logoutId;

        if (User?.Identity.IsAuthenticated == true)
        {
            var idp = User.FindFirst(JwtClaimTypes.IdentityProvider)?.Value;
            if (idp != null && idp != IdentityServer4.IdentityServerConstants.LocalIdentityProvider)
            {
                var providerSupportsSignout = await HttpContext.GetSchemeSupportsSignOutAsync(idp);
                if (providerSupportsSignout)
                {
                    if (LogoutId == null)
                    {
                        // if there's no current logout context, we need to create one
                        // this captures necessary info from the current logged in user
                        // before we signout and redirect away to the external IdP for signout
                        LogoutId = await _interaction.CreateLogoutContextAsync();
                    }

                    ExternalAuthenticationScheme = idp;
                }
            }

            // delete local authentication cookie
            await _signInManager.SignOutAsync();

            // raise the logout event
            await _events.RaiseAsync(new UserLogoutSuccessEvent(User.GetSubjectId(), User.GetDisplayName()));
        }

        // check if we need to trigger sign-out at an upstream identity provider
        if (TriggerExternalSignout)
        {
            // build a return URL so the upstream provider will redirect back
            // to us after the user has logged out. this allows us to then
            // complete our single sign-out processing.
            string url = Url.Action("Logout", new { logoutId = LogoutId });

            // this triggers a redirect to the external provider for sign-out
            return SignOut(new AuthenticationProperties { RedirectUri = url }, ExternalAuthenticationScheme);
        }

        if (AutomaticRedirectAfterSignOut)
            return Redirect(PostLogoutRedirectUri);
        else
            return Page();
    }

When it gets called, there is a logoutId.当它被调用时,会有一个 logoutId。 It gets the context, but PostLogoutRedirectUri is blank.它获取上下文,但 PostLogoutRedirectUri 为空白。 ClientId and ClientName are also blank, but the context has a field called ClientIds and the first entry is the correct ClientId for my app. ClientId 和 ClientName 也是空白的,但上下文有一个名为 ClientIds 的字段,第一个条目是我的应用程序的正确 ClientId。 The log shows as follows:日志显示如下:

IdentityServer4.Validation.EndSessionRequestValidator: Information: End session request validation success
{
  "SubjectId": "6841dc6c-0bd7-4f72-8f1c-f7czzzzzzzzz",
  "Raw": {
    "post_logout_redirect_uri": "mps.mobile.app://callback"
  }
}
IdentityServer4.Hosting.IdentityServerMiddleware: Information: Invoking IdentityServer endpoint: IdentityServer4.Endpoints.EndSessionCallbackEndpoint for /connect/endsession/callback
IdentityServer4.Endpoints.EndSessionCallbackEndpoint: Information: Successful signout callback.

I am using IdentityModel for the Client App.我正在为客户端应用程序使用 IdentityModel。 I have the logout coded as follows:我的注销编码如下:

        _options = new OidcClientOptions
        {
            Authority = MPSOidc.Authority,
            ClientId = MPSOidc.ClientID,
            Scope = "openid profile myapi offline_access email",
            RedirectUri = MPSOidc.RedirectUri,
            PostLogoutRedirectUri = MPSOidc.RedirectUri,
            ResponseMode = OidcClientOptions.AuthorizeResponseMode.Redirect,
            Browser = new ChromeCustomTabsBrowser(this)
        };

        var oidcClient = new OidcClient(_options);

        var r = new LogoutRequest();

        await oidcClient.LogoutAsync(r);

It seems like the PostLogoutRedirectUri should show up here.似乎 PostLogoutRedirectUri 应该出现在这里。 Does anyone know a way to make this happen?有谁知道实现这一点的方法? If not, can the ClientId be used to get the Client information to find the PostLogoutRedirectUri there?如果没有,是否可以使用ClientId获取Client信息以找到那里的PostLogoutRedirectUri?

Thanks, Jim谢谢,吉姆

Here is what it was.这就是它的样子。 When I logged out on the OidcClient, I didn't pass the ID Token.当我在 OidcClient 上注销时,我没有传递 ID 令牌。 On my client Android app, I had to add the ID Token to the logout request:在我的客户端 Android 应用程序上,我必须将 ID 令牌添加到注销请求中:

          var r = new LogoutRequest()
            {
                IdTokenHint = MPSOidc.Tokens.IdentityToken
            };

That's all it took.这就是全部。 Cheers.干杯。

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

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