From a4de76ee2815ab3975d31143ddada3b27518e1fe Mon Sep 17 00:00:00 2001 From: Jon Bergli Heier Date: Mon, 16 Nov 2020 21:59:48 +0100 Subject: api: Set user on g instead of passing as argument --- inventory/api.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'inventory/api.py') 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() -- cgit v1.2.3