PostLogoutRedirectUri 在带有 SPA(Angular 7 OIDC 客户端)的身份服务器 4 中始终为空

San*_*isy 3 asp.net openid-connect asp.net-core identityserver4 angular

在带有身份服务器的Angular应用程序中使用 Facebook 登录身份验证 4. 在注销方法PostLogoutRedirectUri 上,ClientName、LogoutId始终为空。

private async Task<LoggedOutViewModel> BuildLoggedOutViewModelAsync(string logoutId)
    {
        // get context information (client name, post logout redirect URI and iframe for federated signout)
        var logout = await _interaction.GetLogoutContextAsync(logoutId);

        var vm = new LoggedOutViewModel
        {
            AutomaticRedirectAfterSignOut = AccountOptions.AutomaticRedirectAfterSignOut,
            PostLogoutRedirectUri = logout?.PostLogoutRedirectUri,
            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 (vm.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
                        vm.LogoutId = await _interaction.CreateLogoutContextAsync();
                    }

                    vm.ExternalAuthenticationScheme = idp;
                }
            }
        }

        return vm;
    }
Run Code Online (Sandbox Code Playgroud)

Angular oidc 客户端代码

logout(): Promise<any> {
        return this._userManager.signoutRedirect();
    }
Run Code Online (Sandbox Code Playgroud)

客户端设置

public IEnumerable<Client> GetClients()
        {
            var client = new List<Client>
            {
                new Client
                {
                     ClientId = ConstantValue.ClientId,
                    ClientName = ConstantValue.ClientName,
                    AllowedGrantTypes = GrantTypes.Implicit,
                    AllowAccessTokensViaBrowser = true,
                    RequireConsent = false,
                    RedirectUris =           { string.Format("{0}/{1}", Configuration["IdentityServerUrls:ClientUrl"], "assets/oidc-login-redirect.html"), string.Format("{0}/{1}", Configuration["IdentityServerUrls:ClientUrl"], "assets/silent-redirect.html") },
                    PostLogoutRedirectUris = { string.Format("{0}?{1}", Configuration["IdentityServerUrls:ClientUrl"] , "postLogout=true") },
                    AllowedCorsOrigins =     { Configuration["IdentityServerUrls: ClientUrl"] },

                    AllowedScopes =
                    {
                        IdentityServerConstants.StandardScopes.OpenId,
                        IdentityServerConstants.StandardScopes.Profile,
                        ConstantValue.ClientDashApi
                    },
                    IdentityTokenLifetime=120,
                    AccessTokenLifetime=120
                },
            };
            return client;
        }
Run Code Online (Sandbox Code Playgroud)

添加了 ID

logoutId 始终为空。我能够成功登录facebook返回回调方法。但重定向 uri 始终为空。

参考 IdentityServer4 PostLogoutRedirectUri null

Jam*_*Eby 8

这可能不是你的问题,但当我遇到和你一样的错误时,这是​​我的问题,所以我在这里发布我自己的经验。

我正在关注一个 Pluralsight 视频,该视频正在使用 IdentityServer4 作为 STS 服务器构建一个 Angular 应用程序,它指示我在我正在构建的AuthService中为我的UserManager的配置中设置 post_logout_redirect_uri,如下所示:

var config = {
        authority: 'http://localhost:4242/',
        client_id: 'spa-client',
        redirect_uri: `${Constants.clientRoot}assets/oidc-login-redirect.html`,
        scope: 'openid projects-api profile',
        response_type: 'id_token token',
        post_logout_redirect_uri: `${Constants.clientRoot}`,
        userStore: new WebStorageStateStore({ store: window.localStorage })
    }
    this._userManager = new UserManager(config);
Run Code Online (Sandbox Code Playgroud)

github repo https://github.com/IdentityServer/IdentityServer4/issues/396上的一个旧问题讨论了现在自动设置并且不需要显式设置的事实(请参阅线程的末尾)。一旦我从配置中删除它,我就不再遇到在 AccountController 的 Logout 方法中logoutId为 null的问题:

/// <summary>
/// Show logout page
/// </summary>
[HttpGet]
public async Task<IActionResult> Logout(string logoutId)
Run Code Online (Sandbox Code Playgroud)

所以这对我来说是正确的配置设置:

var config = {
        authority: 'http://localhost:4242/',
        client_id: 'spa-client',
        redirect_uri: `${Constants.clientRoot}assets/oidc-login-redirect.html`,
        scope: 'openid projects-api profile',
        response_type: 'id_token token',
        userStore: new WebStorageStateStore({ store: window.localStorage })
    }
    this._userManager = new UserManager(config);
Run Code Online (Sandbox Code Playgroud)