I adapted the following OAauth2 Spring Cloud examples:
Authserver / SSO
The only change I made was to use JPA on the Authserver side to verify credentials from the database. Everything works well, with the exception of deploying it behind the nginx proxy. As used in the sample applications above, Spring Boot and embedded Tomcat are used. I also set proxy headers correctly:
server.tomcat.protocol-header=X-Forwarded-Proto server.tomcat.remote-ip-header=X-Real-IP
Proxying HTTP works:
accessTokenUri: http://uaa.sample.com/oauth/token userAuthorizationUri: http://uaa.sample.com/oauth/authorize
So far, so good, but I need to use SSL (obviously):
accessTokenUri: https://uaa.sample.com/oauth/token userAuthorizationUri: https://uaa.sample.com/oauth/authorize
If I switch to SSL, I get 401 from my client application after the auth server redirects back from authorization. I grabbed HTTP traffic and it works:
The HTTP traffic for HTTP and HTTPS is exactly the same, except that the correct referent for the last request is set for HTTP (AFAIK, the referent is not checked during OAuth authentication, right?):
HTTP:
GET /login?code=212eRK&state=9prwi2 HTTP/1.1 Host: test.sample.com ... Referer: http://uaa.sample.com/login Cookie: JSESSIONID=401EB8D1D1F4297160D518EC253A0CB5; XSRF-TOKEN=95a00a0d-3362-4e9b-b7eb-45addf2d10b4 ... --- HTTP/1.1 302 Found
HTTPS:
GET /login?code=212eRK&state=9prwi2 HTTP/1.1 Host: test.sample.com ... Cookie: JSESSIONID=401EB8D1D1F4297160D518EC253A0CB5; XSRF-TOKEN=95a00a0d-3362-4e9b-b7eb-45addf2d10b4 ... --- HTTP/1.1 401 Unauthorized
Corresponding log message from the client application:
Authentication request failed: org.springframework.security.authentication.BadCredentialsException: Could not obtain access token.
Any ideas why using proxies and SSL does not work? I am happy to share more code and / or magazine output!
Thanks!!!