【发布时间】:2020-07-15 12:09:04
【问题描述】:
我的 DRF 应用程序中有以下标准响应设置:
response = Response(data=response, status=status.HTTP_200_OK)
然后,我尝试使用 response.set_cookie() 调用将拆分 JWT header.payload 和 signature 添加到响应标头中,如下所示:
max_age = 365 * 24 * 60 * 60
expires = datetime.datetime.utcnow() + datetime.timedelta(seconds=max_age)
response.set_cookie(
key='JWT_ACCESS_HEADER_PAYLOAD',
value=header_payload,
httponly=False,
expires=expires.strftime("%a, %d-%b-%Y %H:%M:%S UTC"),
max_age=max_age
)
response.set_cookie(
key='JWT_ACCESS_SIGNATURE',
value=signature,
httponly=True,
expires=expires.strftime("%a, %d-%b-%Y %H:%M:%S UTC"),
max_age=max_age
)
return response
到目前为止,我看不出我所做的有什么问题:
然而,出于某种原因,在客户端设置的唯一 cookie 如下:
我在这里做错了什么??
标头中的实际输出似乎是有效的 SetCookie 值:
JWT_ACCESS_HEADER_PAYLOAD=aSasas; expires=Sat, 03-Apr-2021 10:24:31 GMT; Max-Age=31536000; Path=/
JWT_ACCESS_SIGNATURE=asaSasaS; expires=Sat, 03-Apr-2021 10:24:31 GMT; HttpOnly; Max-Age=31536000; Path=
注意在 localhost 上运行...如果有帮助?
【问题讨论】:
标签: python django cookies django-rest-framework session-cookies