JWT token loaded from a file
metanav opened this issue · comments
It would be more useful to have (the bulky) JWT token be loaded from a file.
You could use bash
to read the token from a file
http --auth-type=jwt --auth='$(cat mytoken.txt):' example.org
Thanks! BTW, It worked after removing single quotes.
thank you @flazzarini for your help.
@metanav: I've added the question here to FAQs section at https://github.com/teracyhq/httpie-jwt-auth/tree/develop#faqs
If you use bash
shell you should use double quotes (") instead of single ones('), it is very crutial here!
You could use
bash
to read the token from a file
http --auth-type=jwt --auth="$(cat mytoken.txt):" example.org
https://stackoverflow.com/questions/6697753/difference-between-single-and-double-quotes-in-bash
It would be nice to have the simple --auth=@filename
syntax like httpie uses for loading JSON data, but the "$(cat auth.token)"
works pretty well. One thing to note is that if you were using something like http POST https://my.domain.com/auth/gettoken | jq .id_token > auth.token
you might have issues. In this case you need to pass the -r
to jq
so that it removes double quotes before outputting the value, otherwise in the file you have literally "veryLongJWTString"
with the double quotes, which makes it not a valid JWT anymore, so jq -r .id_token > auth.token
will get you a valid JWT you can use with "$(cat auth.token)"
and this plugin.