Example #1
0
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
Example #2
0
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)
Example #3
0
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)
Example #4
0
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
Example #5
0
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
Example #6
0
 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
Example #7
0
def load_grant(client_id, code):  # pragma: no cover
    return OAuthGrant.get(client_id, code)
Example #8
0
def test_grant_make_key():
    client_id = str(uuid4())
    code = 'foobar'
    key = '{}:{}'.format(client_id, code)
    assert OAuthGrant.make_key(client_id, code) == key
Example #9
0
def load_grant(client_id, code):  # pragma: no cover
    return OAuthGrant.get(client_id, code)
Example #10
0
def test_grant_make_key():
    client_id = str(uuid4())
    code = 'foobar'
    key = '{}:{}'.format(client_id, code)
    assert OAuthGrant.make_key(client_id, code) == key
Example #11
0
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
Example #12
0
def test_grant_make_key():
    client_id = str(uuid4())
    code = 'foobar'
    key = f'{client_id}:{code}'
    assert OAuthGrant.make_key(client_id, code) == key