gpt4 book ai didi

java - 服务端如何返回 JWT token 给客户端?

转载 作者:搜寻专家 更新时间:2023-11-01 02:19:34 28 4
gpt4 key购买 nike

这是我第一次接触 JWT token ,我想知道这个 token 在首次创建后如何返回给客户端。

它应该出现在 Authorization : Bearer header 中吗?

通常,客户端在每次请求时传递 Authorization : Bearer header 中的 token 。
我想知道在用户通过身份验证并创建 token 后,服务器如何将此 token 传递给客户端。也在同一个标​​题中?在不同的标题中?

在我的情况下,服务器将生成 token 而不是作为响应而是作为请求的一部分。

例如:-

用户将登录到门户,然后单击指向授权应用程序的链接。包含用户声明的 JWT 将作为请求的一部分传递给授权应用程序。
这里最好的方法是什么?获取还是发布?标题(哪个)?请求参数?发布正文?谢谢!

最佳答案

没有关于如何将 JWT token 返回给客户端的标准,但是,检查这个 URL,它回答了你的问题

https://github.com/dwyl/hapi-auth-jwt2/issues/82#issuecomment-129873082

putting the JWT token in the Authorization header gives us flexibility to send an actual response in a web application. For a REST-only App/API you are free to send the JWT as the response body or a cookie. What matters is how the client stores the JWT and sends it back to the Server, which is done in the Authorization header (or Cookie or URL Token if you prefer) 👍

As for this existing in the "wild", I have not seen an example of the server sending an Authorisation header to the client, but there is nothing in the spec to suggest this is an anti-pattern. see: http://self-issued.info/docs/draft-ietf-oauth-v2-bearer.html

If you want to stick to the guidelines you would do follow this example: http://self-issued.info/docs/draft-ietf-oauth-v2-bearer.html#ExAccTokResp

关于java - 服务端如何返回 JWT token 给客户端?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51503024/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com