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

Ability for Environment variables to reference Request variables

Open gsimardnet opened this issue 2 years ago • 1 comments

Hi have two environments "Local" and "Sandbox" but they don't use the same kind of authentication. "Local" is using basic authentication and "Sandbox" uses a bearer token.

Local

@myCredentials= XXXXXXXX

###
GET https://{{myHost}}/path/
Authorization: Basic {{myCredentials}}

Sandbox

@authToken = {{authenticationRequest.response.body.$.access_token}}

###
GET https://{{myHost}}/path/
Authorization: Bearer {{authToken}}

"myCredentials" is a constant value but "authToken" is a request variable.

I would like to combine these two request in one.

GET https://{{myHost}}/path/
Authorization: {{myAuth}}

I thought I would be able to define my environments like this but it doesn't work.

{
    "rest-client.environmentVariables": {       
        "Local": {
            "myAuth": "Basic XXXXXXXX"
        },
        "Sandbox": {
            "myAuth": "Bearer {{authenticationRequest.response.body.$.access_token}}"
        }
    }
}

What would be the solution ?

gsimardnet avatar May 11 '22 16:05 gsimardnet

We should also be able to reference a system variable :

{
    "rest-client.environmentVariables": {       
        "Sandbox": {
            "myAuth": "Bearer {{$aadV2Token appOnly}}"
        }
    }
}

gsimardnet avatar May 11 '22 18:05 gsimardnet