def access_token(self): if self.id in __volatile_tokens__: tok, expires = __volatile_tokens__[self.id] if datetime.utcnow() > expires: # Remove access token from pool, return new one del __volatile_tokens__[self.id] return self.access_token else: return tok else: # first time getting access token, or perhaps it expired? tok, expires = new_token(self.provider_module, self.refresh_token, self.client_id, self.client_secret) validate_token(self.provider_module, tok) self.set_access_token(tok, expires) return tok
def access_token(self): if self.id in __volatile_tokens__: tok, expires = __volatile_tokens__[self.id] if datetime.utcnow() > expires: # Remove access token from pool, return new one del __volatile_tokens__[self.id] return self.access_token else: return tok else: # first time getting access token, or perhaps it expired? tok, expires = new_token(self.refresh_token, self.client_id, self.client_secret) validate_token(tok) self.set_access_token(tok, expires) return tok
def verify(self): if self.id in __volatile_tokens__: tok, expires = __volatile_tokens__[self.id] if datetime.utcnow() > expires: del __volatile_tokens__[self.id] return self.verify() else: try: return validate_token(self.provider_module, tok) except AuthError: del __volatile_tokens__[self.id] raise else: tok, expires = new_token(self.provider_module, self.refresh_token) valid = validate_token(self.provider_module, tok) self.set_access_token(tok, expires) return valid
def access_token(self): from inbox.oauth import new_token, validate_token if self.id in __volatile_tokens__: tok, expires = __volatile_tokens__[self.id] if datetime.utcnow() > expires: # Remove access token from pool, return new one del __volatile_tokens__[self.id] return self.access_token else: return tok else: # first time getting access token, or perhaps it expired? tok, expires = new_token(self.refresh_token) if validate_token(tok): self.set_access_token(tok, expires) return tok else: return None
def _new_token(self): try: return new_token(self.provider_module, self.refresh_token, self.client_id, self.client_secret) except ConnectionError as e: log.error( 'ConnectionError', message=u"Error while getting access token: {}".format(e), account_id=self.id) raise except OAuthInvalidGrantError as e: log.error( 'InvalidGrantError', message=u"Error while getting access token: {}".format(e), account_id=self.id) raise except OAuthError as e: log.error( 'OAuthError', message=u"Error while getting access token: {}".format(e), account_id=self.id) raise
def _new_token(self): try: return new_token(self.provider_module, self.refresh_token, self.client_id, self.client_secret) except ConnectionError as e: log.error('ConnectionError', message=u"Error while getting access token: {}" .format(e), account_id=self.id) raise except OAuthInvalidGrantError as e: log.error('InvalidGrantError', message=u"Error while getting access token: {}" .format(e), account_id=self.id) raise except OAuthError as e: log.error('OAuthError', message=u"Error while getting access token: {}" .format(e), account_id=self.id) raise