Exemple #1
0
 def __init__(self, urlhost, config):
     super(OAuthAuthenticator, self).__init__()
     assert isinstance(config, oauth.OAuthConfig)
     self.urlhost = urlhost
     self.config = config
     self._lock = threading.Lock()
     self._access_token = oauth.load_access_token(self.urlhost, self.config)
Exemple #2
0
 def authorize(self, request):
   with self._lock:
     if not self._access_token_known:
       self._access_token = oauth.load_access_token(self.urlhost, self.config)
       self._access_token_known = True
     if self._access_token:
       request.headers['Authorization'] = 'Bearer %s' % self._access_token
Exemple #3
0
 def __init__(self, urlhost, config):
   super(OAuthAuthenticator, self).__init__()
   assert isinstance(config, oauth.OAuthConfig)
   self.urlhost = urlhost
   self.config = config
   self._lock = threading.Lock()
   self._access_token = oauth.load_access_token(self.urlhost, self.config)
Exemple #4
0
 def authorize(self, request):
     with self._lock:
         if not self._access_token_known:
             self._access_token = oauth.load_access_token(
                 self.urlhost, self.config)
             self._access_token_known = True
         if self._access_token:
             request.headers[
                 'Authorization'] = 'Bearer %s' % self._access_token
Exemple #5
0
 def authorize(self, request):
   with self._lock:
     # Load from cache on a first access.
     if not self._access_token:
       self._access_token = oauth.load_access_token(self.urlhost, self.config)
     # Refresh if expired.
     need_refresh = True
     if self._access_token:
       if self._access_token.expires_at is not None:
         # Allow 5 min of clock skew.
         now = datetime.datetime.utcnow() + datetime.timedelta(seconds=300)
         need_refresh = now >= self._access_token.expires_at
       else:
         # Token without expiration time never expired.
         need_refresh = False
     if need_refresh:
       self._access_token = oauth.create_access_token(
           self.urlhost, self.config, False)
     if self._access_token:
       request.headers['Authorization'] = (
           'Bearer %s' % self._access_token.token)
Exemple #6
0
 def authorize(self, request):
     with self._lock:
         # Load from cache on a first access.
         if not self._access_token:
             self._access_token = oauth.load_access_token(
                 self.urlhost, self.config)
         # Refresh if expired.
         need_refresh = True
         if self._access_token:
             if self._access_token.expires_at is not None:
                 # Allow 5 min of clock skew.
                 now = datetime.datetime.utcnow() + datetime.timedelta(
                     seconds=300)
                 need_refresh = now >= self._access_token.expires_at
             else:
                 # Token without expiration time never expired.
                 need_refresh = False
         if need_refresh:
             self._access_token = oauth.create_access_token(
                 self.urlhost, self.config, False)
         if self._access_token:
             request.headers['Authorization'] = ('Bearer %s' %
                                                 self._access_token.token)
Exemple #7
0
 def __init__(self, urlhost, options):
   super(OAuthAuthenticator, self).__init__()
   self.urlhost = urlhost
   self.options = options
   self._lock = threading.Lock()
   self._access_token = oauth.load_access_token(self.urlhost, self.options)