diff --git a/app/authentication/auth.py b/app/authentication/auth.py index 208d9117e..98212dd94 100644 --- a/app/authentication/auth.py +++ b/app/authentication/auth.py @@ -1,11 +1,10 @@ -from flask import request, _request_ctx_stack, current_app +from flask import request, _request_ctx_stack, current_app, g from sqlalchemy.exc import DataError from sqlalchemy.orm.exc import NoResultFound from notifications_python_client.authentication import decode_jwt_token, get_token_issuer from notifications_python_client.errors import TokenDecodeError, TokenExpiredError, TokenIssuerError -from app.dao.api_key_dao import get_model_api_keys from app.dao.services_dao import dao_fetch_service_by_id @@ -50,6 +49,7 @@ def requires_auth(): raise AuthError("Invalid token: iss not provided", 403) if client == current_app.config.get('ADMIN_CLIENT_USER_NAME'): + g.service_id = current_app.config.get('ADMIN_CLIENT_USER_NAME') return handle_admin_key(auth_token, current_app.config.get('ADMIN_CLIENT_SECRET')) try: @@ -74,6 +74,7 @@ def requires_auth(): if api_key.expiry_date: raise AuthError("Invalid token: API key revoked", 403) + g.service_id = api_key.service_id _request_ctx_stack.top.api_user = api_key return else: diff --git a/app/notifications/rest.py b/app/notifications/rest.py index 126f0feee..fe3210e4d 100644 --- a/app/notifications/rest.py +++ b/app/notifications/rest.py @@ -36,8 +36,6 @@ from app.schemas import ( ) from app.service.utils import service_allowed_to_send_to from app.utils import pagination_links -from app import redis_store -from app.clients import redis notifications = Blueprint('notifications', __name__)