# Path: invenio_oauth2server/provider.py
# def get_user(email, password, *args, **kwargs):
# def get_token(access_token=None, refresh_token=None):
# def get_client(client_id):
# def save_token(token, request, *args, **kwargs):
# def login_oauth2_user(valid, oauth):
# 
# Path: invenio_oauth2server/proxies.py



import sys
from functools import wraps
from flask import abort, current_app, request, session
from flask_login import current_user
from six import reraise
from werkzeug.exceptions import Unauthorized
from .provider import oauth2
from .proxies import current_oauth2server
#
# Invenio is free software; you can redistribute it and/or modify it
# under the terms of the MIT License; see LICENSE file for more details.

"""Useful decorators for checking authentication and scopes."""





def require_api_auth(allow_anonymous=False):
    """Decorator to require API authentication using OAuth token.

    :param allow_anonymous: Allow access without OAuth token
        (default: ``False``).
    """
    def wrapper(f):
        """Wrap function with oauth require decorator."""
        f_oauth_required = oauth2.require_oauth()(f)

        @wraps(f)
        def decorated(*args, **kwargs):
            """Require OAuth 2.0 Authentication."""
            if not hasattr(current_user, 'login_via_oauth2'):
                if not current_user.is_authenticated:
                    if allow_anonymous:
                        return f(*args, **kwargs)
                    abort(401)
                if current_app.config['ACCOUNTS_JWT_ENABLE']:
                    # Verify the token

# Path: invenio_oauth2server/provider.py
# def get_user(email, password, *args, **kwargs):
# def get_token(access_token=None, refresh_token=None):
# def get_client(client_id):
# def save_token(token, request, *args, **kwargs):
# def login_oauth2_user(valid, oauth):
# 
# Path: invenio_oauth2server/proxies.py



# Path: invenio_oauth2server/decorators.py
import sys
from functools import wraps
from flask import abort, current_app, request, session
from flask_login import current_user
from six import reraise
from werkzeug.exceptions import Unauthorized
from .provider import oauth2
from .proxies import current_oauth2server

#
# Invenio is free software; you can redistribute it and/or modify it
# under the terms of the MIT License; see LICENSE file for more details.

"""Useful decorators for checking authentication and scopes."""





def require_api_auth(allow_anonymous=False):
    """Decorator to require API authentication using OAuth token.

    :param allow_anonymous: Allow access without OAuth token
        (default: ``False``).
    """
    def wrapper(f):
        """Wrap function with oauth require decorator."""
        f_oauth_required = oauth2.require_oauth()(f)

        @wraps(f)
        def decorated(*args, **kwargs):
            """Require OAuth 2.0 Authentication."""
            if not hasattr(current_user, 'login_via_oauth2'):
                if not current_user.is_authenticated:
                    if allow_anonymous:
                        return f(*args, **kwargs)
                    abort(401)
                if current_app.config['ACCOUNTS_JWT_ENABLE']:
                    # Verify the token

                    current_oauth2server.jwt_verification_factory(