Esempio n. 1
0
def parse_api_key(request):
    auth_header = request.headers.get("Authorization")
    if not auth_header:
        return None, "No auth header!"

    parts = auth_header.split(':')
    if len(parts) != 2 or parts[0].strip() != 'api-key':
        return None, "Invalid auth header!"

    api_key = parts[1].strip()
    user = Repository.find_user_by_api_key(api_key)
    if not user:
        return None, "Invalid API Key."

    return user, None
Esempio n. 2
0
def parse_api_key(request):
    auth_header = request.headers.get('Authorization')
    if not auth_header:
        return None, "You must specify an Authorization header."

    parts = auth_header.split(':')
    if len(parts) != 2 or parts[0].strip() != 'api-key':
        return None, "Invalid auth header"

    api_key = parts[1].strip()
    user = Repository.find_user_by_api_key(api_key)
    if not user:
        return None, "Invalid API Key, no user with this account."

    return user, None