My sample application work on local environment. But, it does not work on Java8 standard environment. The following project is the sample application project.
https://github.com/nosix/appengine-java8-spring-oauth2
The following error occurs in Java8 standard environment:
Authentication Failed: Could not obtain access token
I added logs to the source code of Spring OAuth and investigated the cause. The cause of the error seems to be that the session data has been lost.
It operated as follows:
preservedState is null in AuthorizationCodeAccessTokenProvider::getParametersForTokenRequest. So, InvalidRequestException is thrown. This is the cause of the error.
setPreservedState method is called in OAuth2RestTemplate::acquireAccessToken. At that time, preservedState is set to null.
DefaultOAuth2ClientContext instance has preservedState. preservedState of DefaultOAuth2ClientContext instance is null in Java8 standard environment. But, It is not null in the local environment.
DefaultOAuth2ClientContext instance are stored in the session. I understand that it is stored on memory in the local environment and in the data store in the standard environment.
From the above, I guessed that the session data was lost.
I was stuck in the investigation. Is there information that serves as a clue for solving?