Exemplo n.º 1
0
    async def __call__(self):
        user = get_authenticated_user(self.request)
        data = {
            'iat': datetime.utcnow(),
            'exp': datetime.utcnow() + timedelta(seconds=self.token_timeout),
            'id': user.id
        }
        jwt_token = jwt.encode(data,
                               app_settings['jwt']['secret']).decode('utf-8')

        await notify(UserRefreshToken(user, jwt_token))

        return {'exp': data['exp'], 'token': jwt_token}
Exemplo n.º 2
0
    async def __call__(self):
        user = get_authenticated_user()
        data = {
            "iat": datetime.utcnow(),
            "exp": datetime.utcnow() + timedelta(seconds=self.token_timeout),
            "id": user.id,
        }
        jwt_token = jwt.encode(
            data, app_settings["jwt"]["secret"], algorithm=app_settings["jwt"]["algorithm"]
        ).decode("utf-8")

        await notify(UserRefreshToken(user, jwt_token))

        return {"exp": data["exp"], "token": jwt_token}
Exemplo n.º 3
0
    async def __call__(self):
        user = get_authenticated_user()

        data = {
            "iat": datetime.utcnow(),
            "exp": datetime.utcnow() + timedelta(seconds=app_settings["jwt"]["token_expiration"]),
            "id": user.id,
        }

        session_manager = query_utility(ISessionManagerUtility)
        if session_manager is not None:
            try:
                session = await session_manager.refresh_session(user.id, user._v_session)
                data["session"] = session
            except AttributeError:
                raise HTTPPreconditionFailed("Session manager configured but no session on jwt")

        jwt_token = jwt.encode(
            data, app_settings["jwt"]["secret"], algorithm=app_settings["jwt"]["algorithm"]
        ).decode("utf-8")

        await notify(UserRefreshToken(user, jwt_token))

        return {"exp": data["exp"], "token": jwt_token}