Exemple #1
0
 def update_token(self, user_name, token):
     user_token = db.UserToken.by_user_name(user_name=user_name)
     # Create the user if it does not exist
     if not user_token:
         user_token = db.UserToken()
         user_token.user_name = user_name
     # Save the new token
     user_token.access_token = token['access_token']
     user_token.token_type = token['token_type']
     user_token.refresh_token = token.get('refresh_token')
     user_token.expires_in = token['expires_in']
     model.Session.add(user_token)
     model.Session.commit()
Exemple #2
0
    def save_token(self, user_name, new_token):
        log.debug('--------UPDATE: CALLED')
        user_token = db.UserToken.by_user_name(user_name=user_name)
        # Create the user if it does not exist
        if not user_token:
            user_token = db.UserToken()
            user_token.user_name = user_name
        # Save the new token
        user_token.access_token = new_token['access_token']
        user_token.token_type = new_token['token_type']
        user_token.refresh_token = new_token.get('refresh_token')
        if 'expires_in' in new_token:
            user_token.expires_in = new_token['expires_in']
        else:
            token.expires_in = new_token['exp'] - new_token['iat']

        model.Session.add(user_token)
        model.Session.commit()
    def update_token(self, user_name, token):

        user_token = db.UserToken.by_user_name(user_name=user_name)
        # Create the user if it does not exist
        if not user_token:
            user_token = db.UserToken()
            user_token.user_name = user_name
        # Save the new token
        user_token.access_token = token["access_token"]
        user_token.token_type = token["token_type"]
        user_token.refresh_token = token.get("refresh_token")
        if "expires_in" in token:
            user_token.expires_in = token["expires_in"]
        else:
            access_token = jwt.decode(user_token.access_token, verify=False)
            user_token.expires_in = access_token["exp"] - access_token["iat"]

        model.Session.add(user_token)
        model.Session.commit()