The flow of login and authentication using Google Oauth
- Bob visits
https://lifeofpablo.com the Nginx reverse proxy...
- recieves the request for
lifeofpablo.comfrom Bob - uses the
auth_requestmodule configured for the/validatepath /validateis configured toproxy_passrequests to the authentication service athttps://vouch.oursites.com/validate- if
/validatereturns...- 200 OK then SUCCESS allow Bob through
- 401 NotAuthorized then
- respond to Bob with a 302 redirect to
https://vouch.oursites.com/login?url=https://private.oursites.com
- recieves the request for
Vouch Proxy
https://vouch.oursites.com/validate- recieves the request for private.oursites.com from Bob via Nginx
proxy_pass - looks for a cookie named "oursitesSSO" that contains a JWT
- if the cookie is found, and the JWT is valid
- returns
200 OKto Nginx, which will allow access (bob notices nothing) - if the cookie is NOT found, or the JWT is NOT valid
- return
401 NotAuthorizedto Nginx (which forwards the request on to login)
- recieves the request for private.oursites.com from Bob via Nginx
Bob is first forwarded briefly to
https://vouch.oursites.com/login?url=https://private.oursites.com- clears out the cookie named "oursitesSSO" if it exists
- generates a nonce and stores it in session variable \$STATE
- stores the url
https://private.oursites.comfrom the query string in session variable$requestedURL - respond to Bob with a 302 redirect to Google's OAuth Login form, including the
$STATEnonce
Bob logs into his Google account using Oauth
- after successful login
- Google responds to Bob with a 302 redirect to
https://vouch.oursites.com/auth?state=$STATE
Bob is forwarded to
https://vouch.oursites.com/auth?state=$STATE- if the \$STATE nonce from the url matches the session variable "state"
- make a "third leg" request of Google (server to server) to exchange the OAuth code for Bob's user info including email address bob@oursites.com
- if the email address matches the domain oursites.com (it does)
- issue bob a JWT in the form of a cookie named "oursitesSSO"
- retrieve the session variable
$requestedURLand 302 redirect bob back tohttps://private.oursites.com
Note that outside of some innocuos redirection, Bob only ever sees https://private.oursites.com and the Google Login screen in his browser. While Vouch does interact with Bob's browser several times, it is just to set cookies, and if the 302 redirects work properly Bob will log in quickly.
Once the JWT is set, Bob will be authorized for all other sites which are configured to use https://vouch.oursites.com/validate from the auth_request Nginx module.
The next time Bob is forwarded to google for login, since he has already authorized the Vouch Proxy OAuth app, Google immediately forwards him back and sets the cookie and sends him on his merry way. In some browsers such as Chrome, Bob may not even notice that he logged in using Vouch Proxy.