Пример #1
0
def save_token(token, request, *args, **kwargs):
    client = Client.objects(id=request.client.id).first()
    user = User.objects(id=request.user.id).first()
    toks = Token.objects(client=client,
        user=user)
    #Making sure that every client has only one token connected to a user
    toks.delete()
    
    expires_in = token.pop('expires_in')
    expires = datetime.utcnow() + timedelta(seconds=expires_in)
    
    tok = Token(**token)
    tok.expires = expires
    tok.client = client
    tok.user = user
    tok.scopes = request.scopes
    tok.save()
    return tok
Пример #2
0
def load_token(access_token=None, refresh_token=None):
    if access_token:
        return Token.objects(access_token=access_token).first()
    elif refresh_token:
        return Token.objects(refresh_token=refresh_token).first()