If OAuth verification is required, validate provided token

        :raise: HTTPError if token does not have access
324398
def prepare(self):
        
        requested_access = self.endpoint_access(self.request.method)
        use_oauth = getattr(options, 'use_oauth', None)
        if use_oauth and requested_access is not self.UNAUTHENTICATED_ACCESS:
            token = self.request.headers.get('Authorization', '').split(' ')[-1]
            if token:
                has_access = yield self.verify_token(token, requested_access)
                if not has_access:
                    msg = "'{}' access not granted.".format(requested_access)
                    raise HTTPError(403, msg)
            else:
                msg = 'OAuth token not provided'
                raise HTTPError(401, msg)
585573
def check_token_status(token)
      info = Slack::Web::Client.new(token: token).auth_test
      fail SlackBotManager::InvalidToken unless info && info['ok']
      info
    end
1308187
def validate(self):
        
        endpoint = '/validate'

        payload = dict(accessToken=self.access_token)
        rep = self._ygg_req(endpoint, payload)
        return not bool(rep)
483006
def _validate_token(self):
        
        '''  '''
        
        title = '%s._validate_token' % self.__class__.__name__
    
    # construct access token url
        import requests
        url = 'https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=%s' % self.access_token
    
    # retrieve access token details
        try:
            token_details = requests.get(url).json()
        except:
            raise DriveConnectionError(title)
        if 'error' in token_details.keys():
            raise ValueError('access_token for google drive account is %s' % token_details['error_description'])
    
    # determine collection space
    # https://developers.google.com/drive/v3/web/about-organization
        if 'scope' in token_details.keys():
            service_scope = token_details['scope']
            if service_scope.find('drive.appfolder') > -1:
                self.drive_space = 'appDataFolder'
                if not self.collection_name:
                    self.collection_name = 'App Data Folder'
            elif service_scope.find('drive.photos.readonly') > -1:
                self.drive_space = 'photos'
                if not self.collection_name:
                    self.collection_name = 'Photos'
    
    # determine permissions
    # https://developers.google.com/drive/v3/web/about-auth
            if service_scope.find('readonly') > -1:
                self.permissions_write = False
            if service_scope.find('readonly.metadata') > -1:
                self.permissions_content = False
          
    # TODO refresh token
        if 'expires_in' in token_details.keys():
            from time import time
            expiration_date = time() + token_details['expires_in']
        if 'issued_to' in token_details.keys():
            client_id = token_details['issued_to']
    
        return token_details
1277285
def verify_request(self, uri, http_method='GET', body=None, headers=None,
                       scopes=None):
        """"""
        request = Request(uri, http_method, body, headers)
        request.token_type = self.find_token_type(request)
        request.scopes = scopes
        token_type_handler = self.tokens.get(request.token_type,
                                             self.default_token_type_handler)
        log.debug('Dispatching token_type %s request to %r.',
                  request.token_type, token_type_handler)
        return token_type_handler.validate_request(request), request
1013649
def access_token(self, value, request):
        

        if self.validate(value, request) is not None:
            return None
        
        access_token = AccessToken.objects.for_token(value)
        
        return access_token
458112
def authentication_required(function):
        """"""
        def wrapped(self, *args, **kwargs):
            if not (self.token or self.apiKey):
                msg = "You must be authenticated to use this method"
                raise AuthenticationError(msg)
            else:
                return function(self, *args, **kwargs)
        return wrapped
540912
def authenticated(self, user_token, **validation_context):
        
        token = self.token_storage.get(user_token)
        if token and token.validate(user_token, **validation_context):
            return True

        return False
439171
def get_access_token(self, request, callback=None):
        ""
        raw_token = request.session.get(self.session_key, None)
        verifier = request.GET.get('oauth_verifier', None)
        if raw_token is not None and verifier is not None:
            data = {'oauth_verifier': verifier}
            callback = request.build_absolute_uri(callback or request.path)
            callback = force_text(callback)
            try:
                response = self.request('post', self.provider.access_token_url,
                                        token=raw_token, data=data, oauth_callback=callback)
                response.raise_for_status()
            except RequestException as e:
                logger.error('Unable to fetch access token: {0}'.format(e))
                return None
            else:
                return response.text
        return None
1140496
def check_auth():
    
    if get_oauth_token():
        auth_info = get_auth_info()
        if not auth_info:
            raise MissingTokenInfoException("Could not get token info")
        if datetime.now() >= auth_info['expires_at']:
            msg = (
                'Token is expired. Now %s but valid until %s',
                datetime.now(), auth_info['expires_at']
            )

            log.warn(
                msg[0], *msg[1:]
            )
            raise TokenIsExpired(msg[0] % msg[1:])
    else:
        raise MissingTokenException()
1374436
def validate_token
      token = params[:token]
      return false if token.nil?
      
      user = User.validate_token(token)
      return false if user.nil?
     
      login_user(user)
      return true
    end
1190126
def valid_token?
      uri = URI.join(Teambition::API_DOMAIN, "/api/applications/#{Teambition.client_key}/tokens/check")

      req = Net::HTTP::Get.new(uri)
      req['Authorization'] = "OAuth2 #{token}"

      res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |https|
        https.request(req)
      end
      res.code == '200'
    end
562468
def _verify_auth(self):
        '''
        
        '''

        return self.token and bool(self.application.auth.get_tok(self.token))
1347214
def validate(self):
        

        try:
            resp = self.request().get(self.validate_url, verify=self.verifySSL).json()
        except TokenExpiredError:
            return False
        except AttributeError:
            return False

        if 'error' in resp:
            return False
        return True
1370302
def get_access_token(self, code=None, **params):
        
        if self._access_token is None:
            if code is None:
                raise ValueError(_('Invalid code.'))
            
            self.access_token_dict = self._get_access_token(code, **params)
            try:
                self._access_token = self.access_token_dict['access_token']
            except KeyError, e:
                raise OAuthError("Credentials could not be validated, the provider returned no access token.")
                
        return self._access_token
1371748
def check_token(self, respond):
        
        if respond.status_code == 401:
            self.credential.obtain_token(config=self.config)
            return False
        return True
311470
def check(*args)
      raise_authentication_error unless authenticated?
      params = arguments(args, required: [:client_id, :access_token]).params

      if arguments.client_id
        begin
          get_request("/applications/#{arguments.client_id}/tokens/#{arguments.access_token}", params)
        rescue Github::Error::NotFound
          nil
        end
      else
        raise raise_app_authentication_error
      end
    end