0

I need to take a token from URL, save it and add it into proxy_set_header(nginx). This is the URL:

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

This my code:

location / {
            set $apiToken "";   

        if ($args ~ "^token=(.+)") {
              set $apiToken $1;
            }
        add_header 'Access-Control-Allow-Origin' "*";
        add_header 'Access-Control-Allow-Credentials' 'true' always;
        add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;
        proxy_set_header X-User-custom $apiToken;
 }

I will appreciate any help. Thank you in advance!

1 Answer 1

1

Use $arg_token to get the token parameter in your url.

Sign up to request clarification or add additional context in comments.

2 Comments

you mean to add int in proxy_set_header like that: proxy_set_header $arg_token
i want to add on every request after that

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.