<tfoot id='E7LZl'></tfoot>

    <bdo id='E7LZl'></bdo><ul id='E7LZl'></ul>
  • <legend id='E7LZl'><style id='E7LZl'><dir id='E7LZl'><q id='E7LZl'></q></dir></style></legend>
    <i id='E7LZl'><tr id='E7LZl'><dt id='E7LZl'><q id='E7LZl'><span id='E7LZl'><b id='E7LZl'><form id='E7LZl'><ins id='E7LZl'></ins><ul id='E7LZl'></ul><sub id='E7LZl'></sub></form><legend id='E7LZl'></legend><bdo id='E7LZl'><pre id='E7LZl'><center id='E7LZl'></center></pre></bdo></b><th id='E7LZl'></th></span></q></dt></tr></i><div id='E7LZl'><tfoot id='E7LZl'></tfoot><dl id='E7LZl'><fieldset id='E7LZl'></fieldset></dl></div>

      <small id='E7LZl'></small><noframes id='E7LZl'>

      1. 如何将 JWT 添加到授权标头?

        时间:2023-12-01
        <legend id='eh7ET'><style id='eh7ET'><dir id='eh7ET'><q id='eh7ET'></q></dir></style></legend>
          <bdo id='eh7ET'></bdo><ul id='eh7ET'></ul>
          • <small id='eh7ET'></small><noframes id='eh7ET'>

          • <i id='eh7ET'><tr id='eh7ET'><dt id='eh7ET'><q id='eh7ET'><span id='eh7ET'><b id='eh7ET'><form id='eh7ET'><ins id='eh7ET'></ins><ul id='eh7ET'></ul><sub id='eh7ET'></sub></form><legend id='eh7ET'></legend><bdo id='eh7ET'><pre id='eh7ET'><center id='eh7ET'></center></pre></bdo></b><th id='eh7ET'></th></span></q></dt></tr></i><div id='eh7ET'><tfoot id='eh7ET'></tfoot><dl id='eh7ET'><fieldset id='eh7ET'></fieldset></dl></div>

              <tfoot id='eh7ET'></tfoot>

                <tbody id='eh7ET'></tbody>

                  本文介绍了如何将 JWT 添加到授权标头?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  如下图所述,客户端需要在下一次请求时通过 Authorization Headerjwt 发送回服务器.

                  As described in the following slide, it is necessary that the client sends the jwt back to the server by an Authorization Header at the next request.

                  但是如何定义 Authorization Header 并将 JWT 添加到服务器?

                  But how can I define the Authorization Header and add the JWT to the server?

                  我现在的状态是:

                  1. 用户通过 POST 请求向服务器发送 usernamepassword.
                  2. 服务器创建JWT.
                  3. 服务器将签名后的 JWT 发送回客户端,并将其保存在 cookie 中.
                  1. User sends username and password to the server by a POST request.
                  2. The server creates the the JWT.
                  3. The server sends the signed JWT back to the client and saves it in a cookie.

                  现在我的问题:

                  • 登录时:

                  据我了解,现在有必要将 JWT 发送回服务器.服务器验证令牌并将其发回以完成登录过程.

                  As I understand it, now its necessary to send the JWT back to the server. The server verifies the token and sends it back to finish the login process.

                  如何将 JWT 添加到 Authorization Header?

                  如果运行进程并从计算中接收数据:

                  我是否理解正确,客户端必须将 JWT 从登录发送到服务器,然后将第二个 JWT 与数据一起发送;或者我可以通过 POST 请求发送数据吗?

                  Do I understand right, that the client has to send the JWT from the login to the server and a second JWT with the data; or can I send the data by POST request?

                  推荐答案

                  所以,你对 JWT 来说是非常正确的.从客户端向服务器发送数据时(在创建 JWT 之后),您需要做的就是将其添加到请求标头中.许多人会尝试与 OAuth 保持相同的路径,并添加类似于以下节点片段的 Bearer 令牌:

                  So, You are pretty much correct with JWT. All you need to do when sending data from client to server (after JWT creation), is to add it to the request header. Many folks will try to keep along the same path as OAuth and add a Bearer token similar to the node snippet below:

                  var rp = require('request-promise');
                  options = {
                    method: GET,
                    uri: 'https://www.example.com/api/sample',
                    headers: {
                      Authorization: "Bearer <insert_your_JWT_here>"
                    }
                  }
                  rp(options).then(function(res){
                    <handle_response>
                  }
                  

                  当然,我知道你提到了 PHP,但工作流程是一样的,只是语法不同.

                  Granted I know you mentioned PHP, but the workflows are the same, its just the syntax is different.

                  现在,要验证此令牌是否存在,服务器需要verify() 确认令牌对于已定义的秘密有效.在客户端发出的每个请求中,对于授权端点,您每次都需要发送此令牌.

                  Now, to verify that this token is present, the server would need to verify() that the token is valid with the secret that was defined. In every request made by the client, for an authorized endpoint, you would need to send this token everytime.

                  这篇关于如何将 JWT 添加到授权标头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何验证来自“Sign In with Apple"的代码? 下一篇:我应该如何使用 PHP 和 MySQL(不使用 OAuth)以安全的方式对一组 Web API 实施“基于令牌的身份验证

                  相关文章

                • <i id='MXnjC'><tr id='MXnjC'><dt id='MXnjC'><q id='MXnjC'><span id='MXnjC'><b id='MXnjC'><form id='MXnjC'><ins id='MXnjC'></ins><ul id='MXnjC'></ul><sub id='MXnjC'></sub></form><legend id='MXnjC'></legend><bdo id='MXnjC'><pre id='MXnjC'><center id='MXnjC'></center></pre></bdo></b><th id='MXnjC'></th></span></q></dt></tr></i><div id='MXnjC'><tfoot id='MXnjC'></tfoot><dl id='MXnjC'><fieldset id='MXnjC'></fieldset></dl></div>
                • <small id='MXnjC'></small><noframes id='MXnjC'>

                    <legend id='MXnjC'><style id='MXnjC'><dir id='MXnjC'><q id='MXnjC'></q></dir></style></legend>
                  1. <tfoot id='MXnjC'></tfoot>

                      <bdo id='MXnjC'></bdo><ul id='MXnjC'></ul>