如何讓 Postman 自動複製JWT 登錄後的 Token 到其他API請求?

Save the JWT as a variable

創建一個 global variable.

先在Postman你的登錄API中,打開 test Tab。

輸入下面的代碼

const response = pm.response.json();
pm.globals.set("jwt_token", response.access_token);

使用 Global variable

在 REST API 的 Authentication tab 中,使用變量。

{{jwt_token}}

在這裏插入圖片描述

使用

先 Send 一次 Login API,然後再訪問其他 REST API 即可。

參考資料

using-jwt-to-authenticate-and-authorize-requests-in-postman

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章