示例#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)
示例#2
0
文件: net.py 项目: wacr2008/soui_gyp
 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
示例#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)
示例#4
0
文件: net.py 项目: danfengzi/soui_gyp
 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
示例#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)
示例#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)
示例#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)