Skip to content

Commit

Permalink
client: add logout blueprint
Browse files Browse the repository at this point in the history
  • Loading branch information
jrcastro2 committed May 26, 2023
1 parent f900a60 commit 60a8b20
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 2 additions & 0 deletions invenio_oauthclient/contrib/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def __init__(
request_token_url=None,
precedence_mask=None,
signup_options=None,
logout_url=None,
**kwargs,
):
"""The constructor."""
Expand Down Expand Up @@ -57,6 +58,7 @@ def __init__(
icon=icon,
precedence_mask=precedence_mask,
signup_options=signup_options,
logout_url=logout_url,
params=dict(
base_url=self.base_url,
request_token_params=request_token_params,
Expand Down
22 changes: 21 additions & 1 deletion invenio_oauthclient/views/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from itsdangerous import BadData

from .._compat import _create_identifier
from ..errors import OAuthRemoteNotFound
from ..errors import OAuthRemoteNotFound, OAuthError
from ..handlers import set_session_next_url
from ..handlers.rest import response_handler
from ..proxies import current_oauthclient
Expand Down Expand Up @@ -271,3 +271,23 @@ def rest_disconnect(remote_app):
return _disconnect(remote_app)
except OAuthRemoteNotFound:
abort(404)


@blueprint.route("/<remote_app>/logout")
def logout(remote_app):
"""Client logout view.
This URL will be called when setting `SECURITY_POST_LOGOUT_VIEW = /oauth/<remote_app>/logout`
"""
logout_url = (
current_app.config["OAUTHCLIENT_REMOTE_APPS"]
.get(remote_app, {})
.get("logout_url")
)

if not logout_url:
raise OAuthError(
"Invalid `logout_url` for OAuth app {}".format(remote_app)
)

return redirect(logout_url, code=302)

0 comments on commit 60a8b20

Please sign in to comment.