最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Postman scripting: how to decode token - Stack Overflow

programmeradmin1浏览0评论

I'm using postman with scripting.

  1. First, I perform a request to retrieve a oauth token.

  2. Then, inside the 'Test' tab, I'm using postman scripting to use the received token to set a global (postman) variable.

Additionally, I would like to decode the token, because I want to use information inside the token to set them as variables. The token payload is base 64 url encoded.

How do I do that?

I'm using postman with scripting.

  1. First, I perform a request to retrieve a oauth token.

  2. Then, inside the 'Test' tab, I'm using postman scripting to use the received token to set a global (postman) variable.

Additionally, I would like to decode the token, because I want to use information inside the token to set them as variables. The token payload is base 64 url encoded.

How do I do that?

Share Improve this question edited Jan 7, 2020 at 15:38 hannes neukermans asked Nov 6, 2018 at 8:42 hannes neukermanshannes neukermans 13.3k7 gold badges39 silver badges64 bronze badges 0
Add a comment  | 

1 Answer 1

Reset to default 17

I found this piece of code on the net. It uses atob sandboxed script to decode base 64 encoded payload

const jsonData = JSON.parse(responseBody);
const payload = jsonData.id_token.split('.')[1];  // Assuming the JWT is in id_token
const parsed = JSON.parse(atob(payload));
pm.environment.set('user_id', parsed.user_id); // Assuming user_id is in the payload
发布评论

评论列表(0)

  1. 暂无评论