Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is logout hardcoded? #55

Open
oculos opened this issue Oct 28, 2023 · 4 comments
Open

Is logout hardcoded? #55

oculos opened this issue Oct 28, 2023 · 4 comments

Comments

@oculos
Copy link

oculos commented Oct 28, 2023

I am trying to modify the

@app.route('/logout')

function.

However, even if I erase the decoration and the function, I still get a default behavior for the /logout endpoint, which is a redirect to the root url.

Is it so? Is there a way to configure it differently?

@abompard
Copy link
Member

abompard commented Nov 3, 2023

Hi! Which version of flask-oidc are you running? I don't see a logout route applied to the main app in the current code.

@brucewilson
Copy link

I know this is an old issue but I had the same issue. It took me too long to figure this out but that route is defined in https://github.com/fedora-infra/flask-oidc/blob/develop/flask_oidc/views.py#L78

And, in case this is useful to other people trying to fix logout, this version doesn't log the user out of their keycloak session so I ended up defining a different route ("/logmeout") which does this:

from yarl import URL

@server.route('/logmeout')
@oidc.require_login
def logout():
    url = oidc.client_secrets.get('issuer')
    referer = URL(request.headers.get('Referer'))
    hosturl = referer.origin()

    # make flask-oidc throw away the auth token
    session.pop('oidc_auth_token')

    # make keycloak throw away the session
    return redirect('%s/protocol/openid-connect/logout?client_id=myclient-app&post_logout_redirect_uri=%s' %
        (url, hosturl))

@abompard
Copy link
Member

Thanks for posting here @brucewilson !

It looks like this relies on the RP-Initiated Logout spec, which is not a draft anymore. There is even an Authlib ticket about implementing it there, Authlib being the library we use in flask-oidc. Once they have implemented it, I'd be happy to add it to Flask-OIDC, or review a PR that would add it.

In the meantime I hope your implementation will help other users, thanks again!

@brucewilson
Copy link

Oh, it would be great to have it implemented by flask-oidc!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants