-
Notifications
You must be signed in to change notification settings - Fork 36
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
auth: use invenio session cookie to retrieve user #160
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,11 +14,13 @@ | |
|
||
from bravado.exception import HTTPError | ||
from flask import Blueprint, jsonify, request | ||
from flask_login import current_user | ||
|
||
from reana_commons.errors import (REANASecretAlreadyExists, | ||
REANASecretDoesNotExist) | ||
from reana_commons.k8s.secrets import REANAUserSecretsStore | ||
from reana_server.utils import get_user_from_token | ||
from reana_server.utils import get_user_from_token, \ | ||
_get_user_from_invenio_user | ||
|
||
blueprint = Blueprint('secrets', __name__) | ||
|
||
|
@@ -38,8 +40,8 @@ def add_secrets(): # noqa | |
parameters: | ||
- name: access_token | ||
in: query | ||
description: Required. Secrets owner access token. | ||
required: true | ||
description: Secrets owner access token. | ||
required: false | ||
type: string | ||
- name: overwrite | ||
in: query | ||
|
@@ -112,7 +114,10 @@ def add_secrets(): # noqa | |
} | ||
""" | ||
try: | ||
user = get_user_from_token(request.args.get("access_token")) | ||
if current_user.is_authenticated: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we use the |
||
user = _get_user_from_invenio_user(current_user.email) | ||
else: | ||
user = get_user_from_token(request.args.get('access_token')) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. updated Issue to be created once the PR is merged. Investigate usage of OAuth2Server to generate tokens so we do not need to generate and maintain our own, see OAuth2Server CLI Note: this would interfere with the implementation of the interactive sessions. We are configuring the Notebook to enable token authentication and the token we pass, is the REANA access token. Using token authentication is the most straight-forward implementation, but from now on, we will have a login, and eventually one can generate tokens to access the application from CLI, to be solved in the future... |
||
secrets_store = REANAUserSecretsStore(str(user.id_)) | ||
overwrite = json.loads(request.args.get('overwrite')) | ||
secrets_store.add_secrets(request.json, overwrite=overwrite) | ||
|
@@ -141,8 +146,8 @@ def get_secrets(): # noqa | |
parameters: | ||
- name: access_token | ||
in: query | ||
description: Required. Secrets owner access token. | ||
required: true | ||
description: Secrets owner access token. | ||
required: false | ||
type: string | ||
responses: | ||
200: | ||
|
@@ -194,7 +199,10 @@ def get_secrets(): # noqa | |
} | ||
""" | ||
try: | ||
user = get_user_from_token(request.args.get("access_token")) | ||
if current_user.is_authenticated: | ||
user = _get_user_from_invenio_user(current_user.email) | ||
else: | ||
user = get_user_from_token(request.args.get('access_token')) | ||
secrets_store = REANAUserSecretsStore(str(user.id_)) | ||
user_secrets = secrets_store.get_secrets() | ||
return jsonify(user_secrets), 200 | ||
|
@@ -220,8 +228,8 @@ def delete_secrets(): # noqa | |
parameters: | ||
- name: access_token | ||
in: query | ||
description: Required. API key of the admin. | ||
required: true | ||
description: API key of the admin. | ||
required: false | ||
type: string | ||
- name: secrets | ||
in: body | ||
|
@@ -283,7 +291,10 @@ def delete_secrets(): # noqa | |
} | ||
""" | ||
try: | ||
user = get_user_from_token(request.args.get("access_token")) | ||
if current_user.is_authenticated: | ||
user = _get_user_from_invenio_user(current_user.email) | ||
else: | ||
user = get_user_from_token(request.args.get('access_token')) | ||
secrets_store = REANAUserSecretsStore(str(user.id_)) | ||
deleted_secrets_list = secrets_store.delete_secrets(request.json) | ||
return jsonify(deleted_secrets_list), 200 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Originally, we have set the
access_token
as a required parameter. This is no longer true, can you please update the docstring? This will be applicable for all endpoints which need authentication :).