reactjsopenid-connectoidc-client-js

identity server 4 + oidc-client-js logout redirect


I'm trying to implement OpenId and oidc-client-js in react. Right now I'm stuck in implementing logout function.

From what I understand, I need to set the post_logout_redirect_uri and use signoutRedirect() to logout the user. Logging out the user works, but unfortunately it stays in the identity server logout page. What I need to do is to redirect the user to the post_logout_redirect_uri.

Can someone tell me what am I missing here? Thanks in advance!

This is the URL where I get redirected. https://identityserver.xx.com/Account/Logout?logoutId=CfDJ8Cqm6alCoddAqWl...


Here's my tech stack:


Below is my Identity server admin settings.


Here's the logout code

    logout = async () => {
        try {
            userManager.signoutRedirect({
                id_token_hint: this.user?.id_token,
                post_logout_redirect_uri : process.env.REACT_APP_LOGOFF_REDIRECT_URL,
                state: this.user?.state
            }).then( () => {
                console.log('done signoutRedirect')
            });

            userManager.clearStaleState()
        }catch(error){
            console.log(error);
        }
    }

Solution

  • in AccountController -> BuildLoggedOutViewModelAsync method check AutomaticRedirectAfterSignOut is true when constructing the viewmodel.

      var vm = new LoggedOutViewModel
                {
                    AutomaticRedirectAfterSignOut = AccountOptions.AutomaticRedirectAfterSignOut, //this must return true.
                    PostLogoutRedirectUri = logout?.PostLogoutRedirectUri,
                    ClientName = string.IsNullOrEmpty(logout?.ClientName) ? logout?.ClientId : logout?.ClientName,
                    SignOutIframeUrl = logout?.SignOutIFrameUrl,
                    LogoutId = logoutId
                };
    

    in your view LoggedOut.cshtml check ~/js/signout-redirect.js is included properly.

    @section scripts
    {
        @if (Model.AutomaticRedirectAfterSignOut)
        {
            <script src="~/js/signout-redirect.js"></script>
    
        }
    }
    

    if your logged out page doesn't contain anchor tag with <a id="post-logout-redirect-uri" ...> you probably have mismatching post_logout_redirect_uri configured in request and client.