mirror of
https://github.com/GSA/notifications-api.git
synced 2026-01-30 06:21:50 -05:00
refactor authentication code
moved api_key secret manipulation (generating and getting) into authentiation/utils, and added a property on the model, to facilitate easier matching of authenticated requests and the api keys they used
This commit is contained in:
@@ -1,10 +1,8 @@
|
||||
from flask import request, jsonify, _request_ctx_stack, current_app
|
||||
from notifications_python_client.authentication import decode_jwt_token, get_token_issuer
|
||||
from notifications_python_client.errors import TokenDecodeError, TokenExpiredError
|
||||
from werkzeug.exceptions import abort
|
||||
|
||||
from app.dao.api_key_dao import get_unsigned_secrets
|
||||
from app import api_user
|
||||
from functools import wraps
|
||||
|
||||
|
||||
def authentication_response(message, code):
|
||||
|
||||
12
app/authentication/utils.py
Normal file
12
app/authentication/utils.py
Normal file
@@ -0,0 +1,12 @@
|
||||
from flask import current_app
|
||||
from itsdangerous import URLSafeSerializer
|
||||
|
||||
|
||||
def get_secret(secret):
|
||||
serializer = URLSafeSerializer(current_app.config.get('SECRET_KEY'))
|
||||
return serializer.loads(secret, salt=current_app.config.get('DANGEROUS_SALT'))
|
||||
|
||||
|
||||
def generate_secret(token):
|
||||
serializer = URLSafeSerializer(current_app.config.get('SECRET_KEY'))
|
||||
return serializer.dumps(str(token), current_app.config.get('DANGEROUS_SALT'))
|
||||
Reference in New Issue
Block a user