Nginx exposes multiple phase to process an incoming HTTP Request. Mainly rewrite, access, content, header_filter, and log
You can embed Lua at the access phase, and query your API from there. Some of the Lua libraries of the OpenResty package [1] might help you do that.
And here [2] you can find an example of OAuth support.
[1] http://openresty.org/#Components [2] http://seatgeek.com/blog/dev/oauth-support-for-nginx-with-lu...