1

I am able to take the token from URL but after that, I want to return it at the and of the next one. For example, I have URL like this:

http://localhost:8900/dashboards?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c

I want to take the token and add it at the end of the next request. For example:

http://localhost:8900/home?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c

And so on...

I am stuck at this for a while and I will appreciate any help. Thank you in advance!

Here is my code so far:

location / {
    set $token $arg_token;              

    add_header 'Access-Control-Allow-Credentials' 'true' always;
    add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;
   
proxy_set_header X-WEBAUTH-USER $remote_user;
proxy_set_header X-User-custom $token;
proxy_pass http://localhost:3000;

}
martin_tsv
  • 11
  • 2
  • How exactly do you want to return the next URL? What is making the next request? – Tero Kilkanen Aug 27 '20 at 22:24
  • Hi. I have an app that implements Grafana. User will be able to auto-login from my app into grafana. After that i am able to attach the generated JWT token from my backend in the url(like the first example above). I want to get the token from the URL and add it in the header and Grafana to sent it with every new request with the reverse proxy(Nginx in my case). I was thinking to achieve this like attach the token in the URL to every new request from Grafana, but I am not sure if this is possible. – martin_tsv Aug 28 '20 at 04:25
  • You need to modify Grafana in order to add the tokens to the URLs it generates. It might be possible to implement something like this in nginx, but that would be complex and bug-prone. Why do you need the token in the URL in the first place? It is in the headers anyway and that is the designed location for it... – Tero Kilkanen Aug 28 '20 at 06:04
  • The problem is that I need to send back the token to my backend app to authorize the user. For that reason, I need to get this token from somewhere. That's why I add it to the URL. As I said this token is not from Grafana. If I hardcode the header(e.g.proxy_set_header X-User-custom XXXXXX;) everything is perfect. Nginx passes it with every request and I can send it to my backend. I want to take the JWTt for every user and send it back. If you have any idea how to achieve this please tell me! – martin_tsv Aug 28 '20 at 07:03

0 Answers0