示例#1
0
文件: oauth.py 项目: rbs-pli/inbox
    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
示例#2
0
文件: gmail.py 项目: betoflakes/inbox
    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
示例#3
0
文件: oauth.py 项目: rbs-pli/inbox
    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
示例#4
0
文件: oauth.py 项目: dlitz/inbox
    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
示例#5
0
文件: gmail.py 项目: PaulReiber/inbox
    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
示例#6
0
 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
示例#7
0
 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