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

Variables inside $aadV2Token

Open marhoy opened this issue 3 years ago • 4 comments

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}}",

marhoy avatar Jun 02 '21 07:06 marhoy

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

mthierba avatar Jan 19 '22 19:01 mthierba

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

snerting avatar Jul 11 '22 17:07 snerting

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

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

manufv avatar Jan 18 '23 09:01 manufv

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...

JeffPGMT avatar Aug 02 '23 18:08 JeffPGMT