示例#1
0
    def test_is_expired(self):
        access = {'expires_in': 7200}

        now = datetime.utcnow()
        two_hours_from_now = (datetime.utcnow() + timedelta(hours=2.5))

        access['expiration'] = (datetime.utcnow() + timedelta(seconds=access['expires_in']))
        self.assertTrue(now <= access['expiration'] < two_hours_from_now)

        self.assertFalse(smartcar.is_expired(access['expiration']))

        access['expiration'] = (datetime.utcnow() - timedelta(hours=2.1))

        self.assertTrue(smartcar.is_expired(access['expiration']))
示例#2
0
def maybe_get_fresh_access_tokens(access_tokens):
    if smartcar.is_expired(access_tokens.expiration):
        new_access = client.exchange_refresh_token(access_tokens.refresh)
        return AccessTokens(token=new_access['access_token'],
                            expiration=new_access['expiration'],
                            refresh=new_access['refresh_token'])
    else:
        return access_tokens
示例#3
0
def check_update_car(car):
    if smartcar.is_expired(car.expiration):
        new_access = smartcar_client.exchange_refresh_token(car.refresh_token)
        car.access_token = new_access['access_token']
        car.expiration = new_access['expiration']
        car.refresh_token = new_access['refresh_token']
        car.refresh_expiration = new_access['refresh_expiration']
    return car
def FreshAccessToken(oldToken):
    """returns a fresh token if oldToken is expired"""
    tokenDict = eval(oldToken)
    if smartcar.is_expired(tokenDict['expiration']):
        newToken = clientInstance.exchange_refresh_token(
            tokenDict['refresh_token'])
        return newToken
    else:
        return tokenDict
示例#5
0
        def get_fresh_access():

            self.ass = load_access_from_database()
            if smartcar.is_expired(self.ass['expiration']):
                new_access = client.exchange_refresh_token(
                    self.ass['refresh_token'])
                put_access_into_database(new_access)
                return new_access
            else:
                return self.ass