Huachao / vscode-restclient

REST Client Extension for Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=humao.rest-client
MIT License
5.18k stars 432 forks source link

Variables inside $aadV2Token #855

Open marhoy opened 3 years ago

marhoy commented 3 years ago

I have been able to get authorization with $aadV2Token to work, when defining all variables in the rest-client.environmentVariables object of settings.json.

However, I would much rather read the secrets from a .env-file. That would allow me to automatically / dynamically replace the values when I'm switching between projects. (And I don't want to define them as shell-environment-variables, as that's very static).

But it seems I'm not allowed to use variables inside the $aadV2Token parenthesis?

With aadV2AppUri, aadV2ClientId and aadV2ClientSecret defined in settings.json, this works:

GET https://mysecret.endpoint/health
Ocp-Apim-Subscription-Key: mysecret-subscription-key
Authorization: Bearer {{$aadV2Token appOnly tenantId:mysecret-tenant-id}}

But this does not work:

@tenant_id = mysecret-tenant-id

GET https://mysecret.endpoint/health
Ocp-Apim-Subscription-Key: mysecret-subscription-key
Authorization: Bearer {{$aadV2Token appOnly tenantId:{{tenant_id}}}}

...and in both cases: Imagine that "mysecret..." is replaced with the actual secret :)

What I would ultimately want to do would be to say:

@tenant_id = {{$dotenv TENANT_ID}}
@app_id = {{$dotenv APP_ID}}
@client_id = {{$dotenv CLIENT_ID}}
@client_secret = {{$dotenv CLIENT SECRET}}

...and then use those variables inside the {{$aadV2Token ... }}.

It would be even smoother if I could also utilize the environment-functionality, but that would require me to be able to use .env-variables in the settings.json (not just shell environment variables):

"aadV2TenantId": "{{$dotenv TENANT_ID}}",
mthierba commented 2 years ago

Agreed, would also love to see a more secure way to store secrets. Possibly integrate with this vscode API? https://code.visualstudio.com/api/references/vscode-api#SecretStorage

snerting commented 2 years ago

Where do you find the aadV2AppUri ? In Azure Ad some place?

manufv commented 1 year ago

Where do you find the aadV2AppUri ? In Azure Ad some place?

Use "https://graph.microsoft.com"

JeffPGMT commented 1 year ago

similar Q, first send req w/body as file that contains correct json works fine, but then trying to read the file and traverse the json to the keyId fails, or referencing the reqPostAuth body.* json path does not contain the content/keys, and currently I'm hard-coding the value in getEnrolls, X-API-ID:

How can I read the json in the file noted below and use the keyId value?

AliceBx.json contents... { "keyId": "bla bla bla bla" "keySecrete": "secretebla bla bla" }

.... @bodyX = aliceBx.json //contains key & secret

@name reqPostAuth

send request POST {{baseUrl}}/{{authUrl}} HTTP/1.1 content-type: application/json

< {{bodyX}}

@bodyVal = {{reqPostAuth.request.body.*}} // my expectation of some values @cYear = 2023 @enrollFileDt = 2023-07-31 @getCUrl = oecm/v1/enrollments

@name getEnrolls

send request GET {{baseUrl}}/{{getCUrl}}/{{cYear}}/{{enrollFileDt}} HTTP/1.1 X-API-ID: {{bodyVal.keys.keyId}} //pseudo code, but this changes in AliceBx.json file Authorization : Bearer {{reqPostAuth.response.body.accessToken}}

Thanks JeffP...