Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cannot use variables in [BasicAuth] #898

Closed
andres-lowrie opened this issue Oct 14, 2022 · 4 comments
Closed

cannot use variables in [BasicAuth] #898

andres-lowrie opened this issue Oct 14, 2022 · 4 comments
Milestone

Comments

@andres-lowrie
Copy link

Hello, great tool!

Not sure if this is a bug or just a misunderstanding but I'm trying to use variables in the [BasicAuth] section and it looks like the tool doesn't like it:

test.hurl

POST http://localhost
[BasicAuth]
{{user}}:{{pass}}

and then I call it like

hurl --variable user=bob --variable pass=secret test.hurl

and get back

error: Parsing JSON
  --> passforbasicauth.hurl:2:2
   |
 2 | [BasicAuth]
   |  ^ JSON error
   |

Is that supposed to work?


My use case is one where I want to be able to define the secrets in another file and not in the hurl file itself to make it easy to share it

@jcamiel
Copy link
Collaborator

jcamiel commented Oct 14, 2022

Hi,

Unfortunately, you can't use this syntax for now.

If you want to not expose credentials in the Hurl file, you can do the following

  1. use an Authorization header
POST http://localhost
Authorization: Basic {{digest}}

Where the variable digest have been computed like that:

$ hurl --variable digest=`echo -n 'bob:secret' | base64` test.hurl

Or you can also make a environment variable like this:

$ export HURL_digest=`echo -n 'bob:secret' | base64`
$ hurl test.hurl

In this case, any HURL_foo environment variable is injected as foovariable in the Hurl file.

  1. use --user option but you will add a basic authentication header to all your requests.

We can think about how to improve things for basic authentication, because in most cases you don't want to write your credentials in a file,

@andres-lowrie
Copy link
Author

fair enough. Thanks for looking into this!

@tpluscode
Copy link

I just tried the same and would also ask for variables to work in [BasicAuth].

My reasoning is that having credentials in a .env file in dev env and secrets in CI makes it easier to run hurl in both cases. Otherwise, the necessity to pass credentials from CLI is a little troublesome

@jcamiel
Copy link
Collaborator

jcamiel commented Dec 14, 2023

Hi @tpluscode, @andres-lowrie,

This issue is now merged on master.
You can now write:

POST http://foo.com/login
[BasicAuth]
{{user}}: {{password}}
HTTP 200

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants