diff options
| author | zsloan | 2025-12-03 19:05:46 +0000 |
|---|---|---|
| committer | zsloan | 2025-12-03 19:25:11 +0000 |
| commit | bde56debe8799bdf2005a81d6e621cec5a3e6e23 (patch) | |
| tree | fa1c6dded8e910dd48062cef893b5917b8b9f83d | |
| parent | 4d70be674232e30cf0a0208ab16fdf517542c52b (diff) | |
| download | gn-auth-bde56debe8799bdf2005a81d6e621cec5a3e6e23.tar.gz | |
Add endpoint for getting user details, given user ID
| -rw-r--r-- | gn_auth/auth/authorisation/users/views.py | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/gn_auth/auth/authorisation/users/views.py b/gn_auth/auth/authorisation/users/views.py index 4061e07..cae2605 100644 --- a/gn_auth/auth/authorisation/users/views.py +++ b/gn_auth/auth/authorisation/users/views.py @@ -46,7 +46,8 @@ from gn_auth.auth.errors import ( UserRegistrationError) -from gn_auth.auth.authentication.users import valid_login, user_by_email +from gn_auth.auth.authentication.users import ( + valid_login, user_by_email, user_by_id) from gn_auth.auth.authentication.oauth2.resource_server import require_oauth from gn_auth.auth.authentication.users import User, save_user, set_user_password from gn_auth.auth.authentication.oauth2.models.oauth2token import ( @@ -78,6 +79,22 @@ def user_details() -> Response: **({"group": asdict(the_group)} if the_group else {}) }) +@users.route("/<user_id>", methods=["GET"]) +def get_user(user_id: str) -> Response: + """Fetch user details by user_id.""" + try: + with db.connection(current_app.config["AUTH_DB"]) as conn: + user = user_by_id(conn, uuid.UUID(user_id)) + return jsonify({ + "user_id": str(user.user_id), + "email": user.email, + "name": user.name + }) + except ValueError: + return jsonify({"error": "Invalid user ID format"}), 400 + except NotFoundError: + return jsonify({"error": "User not found"}), 404 + @users.route("/roles", methods=["GET"]) @require_oauth("role") def user_roles() -> Response: |
