yasudacloud / strapi-plugin-sso

MIT License
89 stars 61 forks source link

Logout Route #46

Open devkaH opened 10 months ago

devkaH commented 10 months ago

It's good to use such a package but it's will be better if you add the implementing a logout route by modifying the controllers and adding a handler for logout because the issue that we faced that when for example launch the login for cognito we have the admin page of strapi but when logout, and the second time we login with cognito it redirect directly to strapi admin page, it's normal since we don't launch the logout from cognito

hyudoo commented 10 months ago

I'm experiencing a similar problem when logging in with Keycloak

devkaH commented 10 months ago

@hyudoo Did you find a solution ?

MagedWilliamdevlink commented 1 month ago

i created a middleware that will redirect when i hit the /admin/auth/login to logout url in keycloak:

// src\middlewares\admin-redirect.js
module.exports = (_config, { strapi }) => {

    const redirects = [
        {
            method: 'GET',
            path: '/admin/auth/login',
            handler: (ctx) => ctx.redirect("http://localhost:8080/realms/strapi/protocol/openid-connect/logout?post_logout_redirect_uri=http://localhost:1337/strapi-plugin-sso/oidc/&client_id=strapicli")
            ,
            config: { auth: false },
        }
    ]
    strapi.server.routes(redirects);
};
// and in config/middlewares.js
module.exports = [
...
  { resolve: './src/middlewares/admin-redirect' },
];

i kind of wished there would be a /admin/auth/logout so i could map a redirect for the login and logout separately like so:

{
    method: 'GET',
    path: '/admin/auth/login',
    handler: (ctx) => ctx.redirect('/strapi-plugin-sso/oidc'),
    config: { auth: false },
},
{
    method: 'GET',
    path: '/admin/auth/logout',
    handler: (ctx) => ctx.redirect("http://localhost:8080/realms/strapi/protocol/openid-connect/logout?post_logout_redirect_uri=http://localhost:1337/strapi-plugin-sso/oidc/&client_id=strapicli")
    ,
    config: { auth: false },
}

But unfortunately i couldn't find a way to change the logout button URL, also the above solution work some of the times it may need another refresh for the middleware to catch it (its seem like its a bug in strapi)