Example #1
0
def auth0_mock(jwks, monkeypatch):
    mock_auth0 = MockAuth0()
    mock_userinfo_response = SimpleNamespace(status_code=200,
                                             json=lambda: mock_auth0.userinfo)
    monkeypatch.setattr('landoapi.auth.fetch_auth0_userinfo',
                        lambda token: mock_userinfo_response)
    return mock_auth0
import logging
import os

import requests
from connexion import ProblemException, request
from flask import current_app, g
from jose import jwt

from landoapi.cache import cache
from landoapi.mocks.auth import MockAuth0
from landoapi.systems import Subsystem

logger = logging.getLogger(__name__)

ALGORITHMS = ["RS256"]
mock_auth0 = MockAuth0()


def get_auth_token():
    auth = request.headers.get("Authorization")
    if auth is None:
        raise ProblemException(
            401,
            "Authorization Header Required",
            "Authorization header is required and was not provided",
            type="https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/401",
        )

    if not auth:
        raise ProblemException(
            401,