vscode-restclient icon indicating copy to clipboard operation
vscode-restclient copied to clipboard

How to create a variable from the decoded output of the response body containing JWT accessToken?

Open vivekkumar27june88 opened this issue 3 years ago • 2 comments

Is it possible to create a variable from the decoded output of the response body containing JWT accessToken?

vivekkumar27june88 avatar Sep 02 '22 21:09 vivekkumar27june88

You can find the instructions in the readme:

https://github.com/Huachao/vscode-restclient#request-variables

cbluth avatar Sep 03 '22 18:09 cbluth

The documentation is good. Thanks.

But the ask is valid and would be really nice to have.

In my case (getting the token from the response body, not a header), the token coming in the response, and captured in a variable, has an & encoded as &, so when sending it on the subsequent call, it's rejected because it's not a valid base64 encoded header.

@baseUrl = https://example.com/api

# @name login
POST {{baseUrl}}/api/login HTTP/1.1
Content-Type: application/x-www-form-urlencoded

name=foo&password=bar

###

@authToken = {{login.response.headers.X-AuthToken}}

The @authToken from above will have a value like ... & ..., which will be rejected in the following call, like:

# @name createComment
POST {{baseUrl}}/comments HTTP/1.1
Authorization: {{authToken}}
Content-Type: application/json

{
    "content": "fake content"
}

Would be really nice if we could get the variable with the decoded value, like ... & ...

ivanalfonso-msft avatar Apr 10 '24 17:04 ivanalfonso-msft