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

auth: use invenio session cookie to retrieve user #160

Merged

Conversation

leticiawanderley
Copy link
Member

No description provided.

@leticiawanderley leticiawanderley changed the title Oauth use session cookie auth: use invenio session cookie to retrieve user Jul 25, 2019
@leticiawanderley leticiawanderley force-pushed the oauth-use-session-cookie branch 6 times, most recently from 5635d8e to d80298a Compare July 25, 2019 16:07
@leticiawanderley leticiawanderley added this to In progress in GitLab-Integration via automation Jul 25, 2019
@@ -10,7 +10,7 @@

from flask import Blueprint, jsonify

blueprint = Blueprint('ping', __name__)
blueprint = Blueprint('ping', __name__, url_prefix='/reana-api')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't use /api because of Invenio's /api? If that's the case, we will have to fix the auth on the API application since this is going to break reana-client's calls.

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'))
Copy link
Member

Choose a reason for hiding this comment

The 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 tokens create

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...

@@ -112,7 +112,10 @@ def add_secrets(): # noqa
}
"""
try:
user = get_user_from_token(request.args.get("access_token"))
if current_user.is_authenticated:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use the login_required decorator? Otherwise, we need to return a 403 if the user is not authenticated nor with the session nor with the token (before we were throwing a ValueError on get_user_from_token, catching it and throwing the 403).

)
assert res.status_code == 200
mock_current_user = Mock(is_authenticated=False)
with patch('flask_login.utils._get_user',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use the mock.patch.multiple so it is a bit less indented :) see in RWC.

@@ -112,7 +112,10 @@ def add_secrets(): # noqa
}
Copy link
Member

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 :).

):
res = client.get(
url_for("workflows.get_workflows"),
query_string={"user_id": default_user.id_,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was not introduced by you, but since you are changing the code, could you remove the user_id parameter? It is no longer in the API. Thanks!

make_mock_api_client("reana-workflow-controller")(),
):
# access token needs to be passed instead of user_id
res = client.post(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can remove this access token needs to be passed instead of user_id part of the test.

Diego Rodriguez and others added 2 commits July 26, 2019 10:28
* With the used Invenio packages Flask-Menu is not initialised
  but required by the installed ones (accessing current_menu)
  so we initialise it in REANA Flask extension.
Addresses reanahub#153

Signed-off-by: Leticia Farias Wanderley <leticia.farias.wanderley@cern.ch>
@leticiawanderley leticiawanderley force-pushed the oauth-use-session-cookie branch 6 times, most recently from 48be29f to 4b15bce Compare July 29, 2019 14:47
@leticiawanderley leticiawanderley moved this from In progress to Review in progress in GitLab-Integration Aug 5, 2019
@@ -24,376 +24,325 @@

from reana_server.utils import _create_and_associate_reana_user

GET_USER_MOCK = Mock(return_value=Mock(is_authenticated=False))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could extract this and the mock:

with patch("flask_login.utils._get_user", GET_USER_MOCK):
    ...

To a new fixture in conftest so the test runs inside this context, for example here we do it. I think it will simplify a bit more the changes.

Addresses reanahub#153

Signed-off-by: Leticia Farias Wanderley <leticia.farias.wanderley@cern.ch>
@diegodelemos diegodelemos merged commit b2022f4 into reanahub:api-login Aug 6, 2019
GitLab-Integration automation moved this from Review in progress to Done Aug 6, 2019
@leticiawanderley leticiawanderley deleted the oauth-use-session-cookie branch August 14, 2019 09:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

None yet

2 participants