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

Combining basic-auth & proxy-rewrite #3133

Closed
BFergerson opened this issue Dec 27, 2020 · 2 comments · Fixed by #3139
Closed

Combining basic-auth & proxy-rewrite #3133

BFergerson opened this issue Dec 27, 2020 · 2 comments · Fixed by #3139
Labels
good first issue Good for newcomers

Comments

@BFergerson
Copy link
Member

I am trying to use two plugins to create a sort of password-protected area in my application. I was hoping to use the basic-auth plugin for username/password functionality and proxy-rewrite to automatically add the username to the route. For example, dynamically rerouting requests to host:3000 to host:3000/{username}.

Is this something that falls within the functionalities APISIX aims to cover? Is this something I can achieve with a custom plugin?

@tokers
Copy link
Contributor

tokers commented Dec 27, 2020

It seems we cannot modify uri based on request headers.

I think maybe we can expand the proxy-rewrite, PR's welcome!

@spacewander
Copy link
Member

You may need to change proxy-rewrite like what we have done with fault-injection:

return conf.abort.http_status, core.utils.resolve_var(conf.abort.body, ctx.var)

And use the consumer_name as variable name. See:

apisix/apisix/core/ctx.lua

Lines 174 to 175 in 5377751

elseif key == "consumer_name" then
val = ngx.ctx.api_ctx and ngx.ctx.api_ctx.consumer_name

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

Successfully merging a pull request may close this issue.

3 participants