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)
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)
def login(self, allow_user_interaction): with self._lock: self._access_token = oauth.create_access_token( self.urlhost, self.options, allow_user_interaction) return self._access_token is not None
def login(self, allow_user_interaction): with self._lock: # Forcefully refresh the token. self._access_token = oauth.create_access_token( self.urlhost, self.config, allow_user_interaction) return self._access_token is not None
def login(self, allow_user_interaction): with self._lock: self._access_token = oauth.create_access_token( self.urlhost, self.config, allow_user_interaction) self._access_token_known = True return self._access_token is not None