我的示例應用程序在本地環境中工作。但是,它不適用於Java8標準環境。以下項目是示例應用程序項目。在Java8標準環境發生在Java8標準環境中使用Spring OAuth的問題
https://github.com/nosix/appengine-java8-spring-oauth2
以下錯誤:
Authentication Failed: Could not obtain access token
我添加日誌以彈簧的OAuth的源代碼並調查原因。錯誤的原因似乎是會話數據丟失了。
它操作如下:
preservedState
是AuthorizationCodeAccessTokenProvider::getParametersForTokenRequest
空。所以,InvalidRequestException
被拋出。這是錯誤的原因。
setPreservedState
方法在OAuth2RestTemplate::acquireAccessToken
中調用。那時,preservedState
被設置爲空。
DefaultOAuth2ClientContext
實例有preservedState
。 preservedState
的DefaultOAuth2ClientContext
實例在Java8標準環境中爲null。但是,在本地環境中它不是空的。
DefaultOAuth2ClientContext
實例存儲在會話中。我知道它存儲在本地環境的內存和標準環境的數據存儲中。
從上面,我猜想會議數據丟失了。
我被困在調查中。是否有信息作爲解決問題的線索?
謝謝你,這個作品!我把你的提交中的東西轉換成了Java,但除此之外沒有什麼大問題。我無法相信存儲會話在App Engine中不起作用,儘管他們說它應該:/ – Lili
[The solution](https:/ /github.com/int128/gradleupdate/commit/2405310dd0da4e19cf4d4b55a16f8466c1d62cc8)的作品。我製作了[DatastoreSessionRepository](https://github.com/nosix/appengine-java8-spring-oauth2/blob/master/application/src/main/kotlin/org/musyozoku/appengine/session/DatastoreSessionRepository.kt),指對此。這也適用。非常感謝你! – nosix
對於非Kotlin人員,這可能對複製粘貼有幫助(隨意用明確的代碼替換lombok) https://gist.github.com/lilianaziolek/6851c2f81be81eae2207ec863f41f484 – Lili