From 7ea2f83c505c792a36d17cc0fc13301a885fb732 Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Wed, 4 Jan 2023 06:37:32 +0300 Subject: auth: return group info as part of user details * gn3/app.py: import blueprint from authorisation views inorder to get all endpoints * gn3/auth/authentication/oauth2/views.py: remove the `/user` endpoint * gn3/auth/authorisation/views.py: add the `/user` endpoint and add the group information to the user details. --- gn3/auth/authorisation/views.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'gn3/auth/authorisation') diff --git a/gn3/auth/authorisation/views.py b/gn3/auth/authorisation/views.py index 2a419af..3e9d9b9 100644 --- a/gn3/auth/authorisation/views.py +++ b/gn3/auth/authorisation/views.py @@ -2,10 +2,27 @@ from flask import jsonify, current_app from gn3.auth import db +from .groups import user_group from .roles import user_roles as _user_roles from ..authentication.oauth2.views import oauth2 from ..authentication.oauth2.resource_server import require_oauth +@oauth2.route("/user") +@require_oauth("profile") +def user_details(): + """Return user's details.""" + with require_oauth.acquire("profile") as the_token: + user = the_token.user + with db.connection(current_app.config["AUTH_DB"]) as conn, db.cursor(conn) as cursor: + group = user_group(cursor, user) + + return jsonify({ + "user_id": user.user_id, + "email": user.email, + "name": user.name, + "group": group.maybe(False, lambda grp: grp) + }) + @oauth2.route("/user-roles") @require_oauth def user_roles(): -- cgit v1.2.3