models.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:flask-rest-api 作者: gitgik 项目源码 文件源码
def generate_token(self, user_id):
        """Generates the access token to be used as the Authorization header"""

        try:
            # set up a payload with an expiration time
            payload = {
                'exp': datetime.utcnow() + timedelta(minutes=5),
                'iat': datetime.utcnow(),
                'sub': user_id
            }
            # create the byte string token using the payload and the SECRET key
            jwt_string = jwt.encode(
                payload,
                current_app.config.get('SECRET'),
                algorithm='HS256'
            )
            return jwt_string

        except Exception as e:
            # return an error in string format if an exception occurs
            return str(e)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号