def _validate_token(self, token, scopes_required=None):
        """The actual implementation of validate_token."""
        if scopes_required is None:
            scopes_required = []
        scopes_required = set(scopes_required)

        token_info = None
        valid_token = False
        has_required_scopes = False
        if token:
            try:
                token_info = self._get_token_info(token)
            except Exception as ex:
                token_info = {'active': False}
                logger.error('ERROR: Unable to get token info')
                logger.error(str(ex))

            valid_token = token_info.get('active', False)

            if 'aud' in token_info and \
                    current_app.config['OIDC_RESOURCE_CHECK_AUD']:
                valid_audience = False
                aud = token_info['aud']
                clid = self.client_secrets['client_id']
                if isinstance(aud, list):
                    valid_audience = clid in aud
                else:
                    valid_audience = clid == aud

                if not valid_audience:
                    logger.error('Refused token because of invalid '
                                 'audience')
                    valid_token = False

            if valid_token:
                token_scopes = token_info.get('scope', '').split(' ')
            else:
                token_scopes = []
            has_required_scopes = scopes_required.issubset(
                set(token_scopes))

            if not has_required_scopes:
                logger.debug('Token missed required scopes')

        if (valid_token and has_required_scopes):
            g.oidc_token_info = token_info
            return True

        if not valid_token:
            return 'Token required but invalid'
        elif not has_required_scopes:
            return 'Token does not have required scopes'
        else:
            return 'Something went wrong checking your token'
def _validate_token ( self , token , scopes_required = None ) : if scopes_required is None : scopes_required = [ ] scopes_required = set ( scopes_required ) token_info = None valid_token = False has_required_scopes = False if token : try : token_info = self . _get_token_info ( token ) except Exception as ex : token_info = { 'active' : False } logger . error ( 'ERROR: Unable to get token info' ) logger . error ( str ( ex ) ) valid_token = token_info . get ( 'active' , False ) if 'aud' in token_info and current_app . config [ 'OIDC_RESOURCE_CHECK_AUD' ] : valid_audience = False aud = token_info [ 'aud' ] clid = self . client_secrets [ 'client_id' ] if isinstance ( aud , list ) : valid_audience = clid in aud else : valid_audience = clid == aud if not valid_audience : logger . error ( 'Refused token because of invalid ' 'audience' ) valid_token = False if valid_token : token_scopes = token_info . get ( 'scope' , '' ) . split ( ' ' ) else : token_scopes = [ ] has_required_scopes = scopes_required . issubset ( set ( token_scopes ) ) if not has_required_scopes : logger . debug ( 'Token missed required scopes' ) if ( valid_token and has_required_scopes ) : g . oidc_token_info = token_info return True if not valid_token : return 'Token required but invalid' elif not has_required_scopes : return 'Token does not have required scopes' else : return 'Something went wrong checking your token'
The actual implementation of validate_token.