Héctor
Héctor

Reputation: 26034

Nginx proxy for OAuth2 validation

I have an own OAuth2 provider where you can ask for a token and validate it. I want to protect my REST API (resource server) with OAuth2, so, in every single request, the access token must be validated, against OAuth2 server.

I have been doing this validation in the REST API code itself, by intercepting every request and doing another request to OAuth2 server.

I wonder if there is any way to do it in the Nginx server instead of in the REST API. This way, it would be easier to setup in another REST API, instead of copy/paste the code (or share a library).

Maybe, should I create my own nginx module? Or running an script in every request? If so, how can I do it?

Any advice will be appreciated.

Upvotes: 4

Views: 8378

Answers (1)

David Karlsson
David Karlsson

Reputation: 9686

Yes, you can use the auth-request module in nginx.

Upvotes: 7

Related Questions