def accept_token(self, require_token=False, scopes_required=None,
                           render_errors=True):
        """
        Use this to decorate view functions that should accept OAuth2 tokens,
        this will most likely apply to API functions.

        Tokens are accepted as part of the query URL (access_token value) or
        a POST form value (access_token).

        Note that this only works if a token introspection url is configured,
        as that URL will be queried for the validity and scopes of a token.

        :param require_token: Whether a token is required for the current
            function. If this is True, we will abort the request if there
            was no token provided.
        :type require_token: bool
        :param scopes_required: List of scopes that are required to be
            granted by the token before being allowed to call the protected
            function.
        :type scopes_required: list
        :param render_errors: Whether or not to eagerly render error objects
            as JSON API responses. Set to False to pass the error object back
            unmodified for later rendering.
        :type render_errors: callback(obj) or None

        .. versionadded:: 1.0
        """

        def wrapper(view_func):
            @wraps(view_func)
            def decorated(*args, **kwargs):
                token = None
                if 'Authorization' in request.headers and request.headers['Authorization'].startswith('Bearer '):
                    token = request.headers['Authorization'].split(None,1)[1].strip()
                if 'access_token' in request.form:
                    token = request.form['access_token']
                elif 'access_token' in request.args:
                    token = request.args['access_token']

                validity = self.validate_token(token, scopes_required)
                if (validity is True) or (not require_token):
                    return view_func(*args, **kwargs)
                else:
                    response_body = {'error': 'invalid_token',
                                     'error_description': validity}
                    if render_errors:
                        response_body = json.dumps(response_body)
                    return response_body, 401, {'WWW-Authenticate': 'Bearer'}

            return decorated
        return wrapper
def accept_token ( self , require_token = False , scopes_required = None , render_errors = True ) : def wrapper ( view_func ) : @ wraps ( view_func ) def decorated ( * args , ** kwargs ) : token = None if 'Authorization' in request . headers and request . headers [ 'Authorization' ] . startswith ( 'Bearer ' ) : token = request . headers [ 'Authorization' ] . split ( None , 1 ) [ 1 ] . strip ( ) if 'access_token' in request . form : token = request . form [ 'access_token' ] elif 'access_token' in request . args : token = request . args [ 'access_token' ] validity = self . validate_token ( token , scopes_required ) if ( validity is True ) or ( not require_token ) : return view_func ( * args , ** kwargs ) else : response_body = { 'error' : 'invalid_token' , 'error_description' : validity } if render_errors : response_body = json . dumps ( response_body ) return response_body , 401 , { 'WWW-Authenticate' : 'Bearer' } return decorated return wrapper
Use this to decorate view functions that should accept OAuth2 tokens,
        this will most likely apply to API functions.

        Tokens are accepted as part of the query URL (access_token value) or
        a POST form value (access_token).

        Note that this only works if a token introspection url is configured,
        as that URL will be queried for the validity and scopes of a token.

        :param require_token: Whether a token is required for the current
            function. If this is True, we will abort the request if there
            was no token provided.
        :type require_token: bool
        :param scopes_required: List of scopes that are required to be
            granted by the token before being allowed to call the protected
            function.
        :type scopes_required: list
        :param render_errors: Whether or not to eagerly render error objects
            as JSON API responses. Set to False to pass the error object back
            unmodified for later rendering.
        :type render_errors: callback(obj) or None

        .. versionadded:: 1.0