def save_grant(client_id, code, request, *args, **kwargs): #TODO: Place the expires time in the settings expires = datetime.utcnow() + timedelta(seconds=8640000) app.logger.debug("Inside save_grant with client_id: {client_id}".format(client_id=client_id)) client = Client.objects(id=client_id).first() #TODO: Exception handling user = User.objects(id=g.user.id).first() app.logger.debug("User-id:{user_id}".format(user_id=g.user.id)) grant = Grant( client=client, code=code['code'], redirect_uri=request.redirect_uri, scopes=request.scopes, #documentation for SQLAlchemy says _scopes=''.join(request.scopes) #confirm user=user, #get_current_user() expires=expires ) grant.save() return grant
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