def save_grant(client_id, code, request, *args, **kwargs): ttl = Config.getInstance().getOAuthGrantTokenTTL() expires = datetime.utcnow() + timedelta(seconds=ttl) grant = OAuthGrant(client_id=client_id, code=code['code'], redirect_uri=request.redirect_uri, user=session.user, scopes=request.scopes, expires=expires) grant.save() return grant
def test_grant_get(mocker): mocker.patch.object(OAuthGrant, '_cache') client_id = str(uuid4()) code = 'foobar' OAuthGrant.get(client_id, code) key = OAuthGrant.make_key(client_id, code) OAuthGrant._cache.get.assert_called_with(key)
def save_grant(client_id, code, request, *args, **kwargs): expires = datetime.utcnow() + timedelta(seconds=120) grant = OAuthGrant(client_id=client_id, code=code['code'], redirect_uri=request.redirect_uri, user=session.user, scopes=request.scopes, expires=expires) grant.save() return grant
def _create_grant_token(**params): params.setdefault('client_id', str(uuid4())) params.setdefault('code', 'foobar') params.setdefault('redirect_uri', 'http://localhost:5000') params.setdefault('user', dummy_user) params.setdefault('scopes', 'api') params.setdefault('expires', datetime.utcnow() + timedelta(seconds=120)) grant = OAuthGrant(**params) return grant
def load_grant(client_id, code): # pragma: no cover return OAuthGrant.get(client_id, code)
def test_grant_make_key(): client_id = str(uuid4()) code = 'foobar' key = '{}:{}'.format(client_id, code) assert OAuthGrant.make_key(client_id, code) == key
def test_grant_make_key(): client_id = str(uuid4()) code = 'foobar' key = f'{client_id}:{code}' assert OAuthGrant.make_key(client_id, code) == key