Skip to content

Commit

Permalink
api: add logout route
Browse files Browse the repository at this point in the history
  • Loading branch information
mvidalgarcia committed Nov 27, 2019
1 parent a128edd commit 0e6f94e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/openapi.json
Expand Up @@ -156,6 +156,7 @@
"summary": "TEMPORARY displays a message about how to access a resource."
}
},
"/api/logout": {},
"/api/me": {
"get": {
"description": "This resource provides basic information about an authenticated user based on the session cookie presence.",
Expand Down
13 changes: 12 additions & 1 deletion reana_server/rest/users.py
Expand Up @@ -11,9 +11,10 @@
import logging
import traceback

from flask import Blueprint, jsonify, request
from flask import Blueprint, jsonify, request, make_response, redirect
from flask_login import current_user

from reana_server.config import REANA_URL
from reana_server.utils import (_create_user, _get_user_from_invenio_user,
_get_users)

Expand Down Expand Up @@ -289,3 +290,13 @@ def get_me():
)
else:
return jsonify({'error': 'User not logged in'}), 401


@blueprint.route('/logout', methods=['GET'])
def _logout():
if current_user.is_authenticated:
resp = make_response(redirect(request.args.get("next")))
resp.delete_cookie('session')
return resp
else:
return jsonify({'error': 'User not logged in'}), 401

0 comments on commit 0e6f94e

Please sign in to comment.