thunder-client-support icon indicating copy to clipboard operation
thunder-client-support copied to clipboard

Parse and format env variable before storage

Open ccourson opened this issue 3 years ago • 3 comments

A login request I perform returns a long authorization token as a text value between double quotes ("). The value cannot be used with the quotes so I have to remove the quotes from the env variable before firing any other request using the token.

Maybe a way to specify the value using regex in a setTo Test? i.e. {{variable/regex/, env}} Another idea might be to add a term to remove quotes sort of like Jinja filters: {{variable|no-quotes, env}}

Thank you for your time. The tool is awesome.

ccourson avatar Aug 10 '22 21:08 ccourson

Thanks @ccourson for the feedback, will add to roadmap.

rangav avatar Aug 10 '22 21:08 rangav

looks like a cool idea, might suit this use-case and other common operations, will look into it more when I got time. Thanks for suggestion. https://jinja.palletsprojects.com/en/3.1.x/templates/

rangav avatar Aug 10 '22 21:08 rangav

Thanks @ccourson for the feedback, will add to roadmap.

Hi rangav,

I have experienced the same problem. Here is some additional information: I use the OAuth2 "Authorization Code with PKCE" and my linked ".env" file has the values encosed in double quotes " just like ccourson stated.

When I press "Generate Token", the URL in the request turns out as follows: (see the %22 for the query param client_id)

https://xxxxxx.b2clogin.com/xxxxxx.onmicrosoft.com/oauth2/v2.0/authorize?p=b2c_1_signinsignup&response_type=code&state=&client_id=%22xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx%22&scope=https://xxxxxx.onmicrosoft.com/api/Read%20offline_access&redirect_uri=https://www.thunderclient.com/oauth/callback&code_challenge=xxxxxx&code_challenge_method=S256

My .env looks like this:

AUTH_SCOPE_READ="https://xxxxxx.onmicrosoft.com/api/Read"
AUTH_AUTHORITY_SIGNIN_SIGNUP="https://xxxxxx.b2clogin.com/xxxxxx.onmicrosoft.com/B2C_1_SignInSignUp"
AUTH_CLIENT_ID="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
AUTH_CLIENT_SECRET="xxxxxxxxxxxxxxxx"
AUTH_REDIRECT_URI="http://localhost:3000/auth/redirect"

I'm not familiar with VS Code Extensions yet, but if you can use NPM packages, I can recommend dotenv to use for parsing so it will adhere to common formatting.

Thank you for this awesome extension! Cheers Peter

qbasic16 avatar Aug 16 '22 19:08 qbasic16

@qbasic16 I have updated the library to dotenv to read .env files in v1.19.3

See all features released https://github.com/rangav/thunder-client-support/releases/tag/v1.19.3

rangav avatar Sep 27 '22 11:09 rangav

This feature is now implemented and published to marketplace, please update to v2.0.0

See all features released https://github.com/rangav/thunder-client-support/releases/tag/v2.0.0

Please let me know your feedback.

@ccourson thanks for suggesting jinja filters, its now implemented in extension.

Remove Quotes

  • When using Set Env Variable in Tests tab Screenshot 2022-11-17 at 11 46 10

  • If you want to remove quotes when using env variable - {{variable | removeQuotes}} Screenshot 2022-11-17 at 15 28 06

rangav avatar Nov 17 '22 11:11 rangav