flask_oauthlib/provider/oauth2.py
def validate_bearer_token(self, token, scopes, request):
        """Validate access token.

        :param token: A string of random characters
        :param scopes: A list of scopes
        :param request: The Request object passed by oauthlib

        The validation validates:

            1) if the token is available
            2) if the token has expired
            3) if the scopes are available
        """
        log.debug('Validate bearer token %r', token)
        tok = self._tokengetter(access_token=token)
        if not tok:
            msg = 'Bearer token not found.'
            request.error_message = msg
            log.debug(msg)
            return False

        # validate expires
        if tok.expires is not None and \
                datetime.datetime.utcnow() > tok.expires:
            msg = 'Bearer token is expired.'
            request.error_message = msg
            log.debug(msg)
            return False

        # validate scopes
        if scopes and not set(tok.scopes) & set(scopes):
            msg = 'Bearer token scope not valid.'
            request.error_message = msg
            log.debug(msg)
            return False

        request.access_token = tok
        request.user = tok.user
        request.scopes = scopes

        if hasattr(tok, 'client'):
            request.client = tok.client
        elif hasattr(tok, 'client_id'):
            request.client = self._clientgetter(tok.client_id)
        return True
def validate_bearer_token(self, token, scopes, request):
        log.debug('Validate bearer token %r', token)
        tok = self._tokengetter(access_token=token)
        if not tok:
            msg = 'Bearer token not found.'
            request.error_message = msg
            log.debug(msg)
            return False

        # validate expires
        if tok.expires is not None and \
                datetime.datetime.utcnow() > tok.expires:
            msg = 'Bearer token is expired.'
            request.error_message = msg
            log.debug(msg)
            return False

        # validate scopes
        if scopes and not set(tok.scopes) & set(scopes):
            msg = 'Bearer token scope not valid.'
            request.error_message = msg
            log.debug(msg)
            return False

        request.access_token = tok
        request.user = tok.user
        request.scopes = scopes

        if hasattr(tok, 'client'):
            request.client = tok.client
        elif hasattr(tok, 'client_id'):
            request.client = self._clientgetter(tok.client_id)
        return True
def validate_bearer_token ( self , token , scopes , request ) : log . debug ( 'Validate bearer token %r' , token ) tok = self . _tokengetter ( access_token = token ) if not tok : msg = 'Bearer token not found.' request . error_message = msg log . debug ( msg ) return False # validate expires if tok . expires is not None and datetime . datetime . utcnow ( ) > tok . expires : msg = 'Bearer token is expired.' request . error_message = msg log . debug ( msg ) return False # validate scopes if scopes and not set ( tok . scopes ) & set ( scopes ) : msg = 'Bearer token scope not valid.' request . error_message = msg log . debug ( msg ) return False request . access_token = tok request . user = tok . user request . scopes = scopes if hasattr ( tok , 'client' ) : request . client = tok . client elif hasattr ( tok , 'client_id' ) : request . client = self . _clientgetter ( tok . client_id ) return True
Validate access token.

        :param token: A string of random characters
        :param scopes: A list of scopes
        :param request: The Request object passed by oauthlib

        The validation validates:

            1) if the token is available
            2) if the token has expired
            3) if the scopes are available
Validate access token .