diff options
author | Jon Bergli Heier <snakebite@jvnv.net> | 2020-11-16 21:59:48 +0100 |
---|---|---|
committer | Jon Bergli Heier <snakebite@jvnv.net> | 2020-11-16 21:59:48 +0100 |
commit | a4de76ee2815ab3975d31143ddada3b27518e1fe (patch) | |
tree | 800bf84c1f79f3586c4130f26096650a34529a2a /inventory/api.py | |
parent | 11ba78d00d86e8cc8e53e0cf333eaccb2b51e2f7 (diff) |
api: Set user on g instead of passing as argument
Diffstat (limited to 'inventory/api.py')
-rw-r--r-- | inventory/api.py | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/inventory/api.py b/inventory/api.py index ef05e33..d374ad1 100644 --- a/inventory/api.py +++ b/inventory/api.py @@ -3,7 +3,7 @@ import functools import time from bson import ObjectId -from flask import Blueprint, jsonify, current_app, request, abort, url_for +from flask import Blueprint, jsonify, current_app, request, abort, url_for, g from flask_pymongo import PyMongo import itsdangerous import jwt @@ -67,7 +67,8 @@ def auth_required(f): user = mongo.db.users.find_one({'_id': user_id}) if not user: abort(403) - return f(user, *args, **kwargs) + g.user = user + return f(*args, **kwargs) return wrapper @@ -271,7 +272,7 @@ def auth_logout(): @app.route('/user') @auth_required -def user_info(user): +def user_info(): url = yarl.URL(current_app.config['OAUTH_URL']).parent / 'api' / 'user' response = requests.get(str(url), headers={'Authorization': request.headers.get('Authorization')}) data = response.json() |