# Path: dashboard/api/exceptions.py
# class AuthError(Exception):
#     def __init__(self, error, status_code):
#         self.error = error
#         self.status_code = status_code


import json
import logging
from functools import wraps
from flask import request
from flask import _request_ctx_stack
from six.moves.urllib.request import urlopen
from jose import jwt
from dashboard.api.exceptions import AuthError

logger = logging.getLogger(__name__)


class AuthorizeAPI(object):
    def __init__(self, app, oidc_config):
        self.app = app
        self.algorithms = "RS256"
        self.auth0_domain = oidc_config.OIDC_DOMAIN  # auth.mozilla.auth0.com
        self.audience = self._get_audience(self.app.config)

    def _get_audience(self, app_config):
        if app_config["SERVER_NAME"] == "localhost:5000":
            return "https://sso.allizom.org"
        else:
            return "https://" + self.app.config.get(
                "SERVER_NAME", "sso.mozilla.com"
            )  # sso.mozilla.com

    # Format error response and append status code
    def get_token_auth_header(self):
        """Obtains the Access Token from the Authorization Header
        """
        auth = request.headers.get("Authorization", None)
        if not auth:

# Path: dashboard/api/exceptions.py
# class AuthError(Exception):
#     def __init__(self, error, status_code):
#         self.error = error
#         self.status_code = status_code


# Path: dashboard/api/idp.py
import json
import logging
from functools import wraps
from flask import request
from flask import _request_ctx_stack
from six.moves.urllib.request import urlopen
from jose import jwt
from dashboard.api.exceptions import AuthError


logger = logging.getLogger(__name__)


class AuthorizeAPI(object):
    def __init__(self, app, oidc_config):
        self.app = app
        self.algorithms = "RS256"
        self.auth0_domain = oidc_config.OIDC_DOMAIN  # auth.mozilla.auth0.com
        self.audience = self._get_audience(self.app.config)

    def _get_audience(self, app_config):
        if app_config["SERVER_NAME"] == "localhost:5000":
            return "https://sso.allizom.org"
        else:
            return "https://" + self.app.config.get(
                "SERVER_NAME", "sso.mozilla.com"
            )  # sso.mozilla.com

    # Format error response and append status code
    def get_token_auth_header(self):
        """Obtains the Access Token from the Authorization Header
        """
        auth = request.headers.get("Authorization", None)
        if not auth:

            raise AuthError(