Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 215
Héctor Avatar asked Mar 08 '23 23:03

Héctor


1 Answers

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

like image 181
David Karlsson Avatar answered Apr 01 '23 03:04

David Karlsson