keycloakify / oidc-spa

Openid connect client for Single Page Applications
https://www.oidc-spa.dev
MIT License
48 stars 6 forks source link

Logout feature : redirectTo should be an url #2

Closed laurentC35 closed 10 months ago

laurentC35 commented 10 months ago

Hi there!

In some cases, we would like to be able to disconnect the user and redirect him to a specific url. Currently the "logout" function returned by the oidcClient only allows 2 possibilities: the current page and the "root" page of the application.

Is it possible to have a 3rd case (or the default case) to redirect to a url passed as a parameter?

Thanks

Simple proposal

      "logout": async ({ redirectTo }) => {
           await userManager.signoutRedirect({
                "post_logout_redirect_uri": (() => {
                    switch (redirectTo) {
                        case "current page":
                            return window.location.href;
                        case "home":
                            return window.location.origin;
                        default:
                            return redirectTo;
                    }
                })()
            });
            return new Promise<never>(() => {});
        },
garronej commented 10 months ago

Hello @laurentC35, sure no problem

garronej commented 10 months ago

Je te propose:

oidc.logout({ redirectTo: "specific url", url: /*...*/ });

Comme ça on garde la type safety.

Au passage, j'ai retirer le paramètre silentSsoUrl au profit de et ajouter publicUrl.

Voir:

https://github.com/garronej/oidc-spa/blob/27d05565856c3e0d164a902bbfb51632923f397c/src/oidc.ts#L48-L61

Je fait l'autre issue et je release une nouvelle version!