簡體   English   中英

部署的應用程序無法將 oauth2 代碼交換為令牌

[英]Deployed app cannot exchange oauth2 code for token

本地一切正常!

但是,在 raspberrypi 上部署到我的 Kubernetes k3s 集群(可通過 https 域訪問)后,oauth2 代碼交換令牌功能不起作用。 我目前支持通過 Google 和 GitHub 進行身份驗證,它們都有這個問題。 以下是日志:

GitHub 登錄失敗:

org.springframework.security.oauth2.core.OAuth2AuthenticationException: 
[invalid_token_response] An error occurred while attempting to retrieve the OAuth 2.0 Access Token Response: Error while extracting response for type [class org.springframework.security.oauth2.core.endpoint.OAuth2AccessTokenResponse] and content type [application/json;charset=utf-8]; 
nested exception is org.springframework.http.converter.HttpMessageNotReadableException: An error occurred reading the OAuth 2.0 Access Token Response: tokenValue cannot be empty; 
nested exception is java.lang.IllegalArgumentException: tokenValue cannot be empty

谷歌登錄失敗:

org.springframework.security.oauth2.core.OAuth2AuthenticationException: 
[invalid_token_response] An error occurred while attempting to retrieve the OAuth 2.0 Access Token Response: I/O error on POST request for "https://www.googleapis.com/oauth2/v4/token": Invalid ECDH ServerKeyExchange signature; 
nested exception is javax.net.ssl.SSLHandshakeException: Invalid ECDH ServerKeyExchange signature

我已經嘗試過的:

I thought it might be a problem with sending https requests from within my Kubernetes cluster, but I connected to the running pod and curled https://google.com and it worked just fine.

大家有遇到過這樣的問題嗎?

@edit 我正在使用 Java 11

@edit2 我的 raaspberrypi 上的 docker 似乎有問題。 冰壺 https 請求工作正常,但在 Java 中使用RestTemplate不起作用

@edit3 發現一個相關問題https://github.com/docker-library/tomcat/issues/182

問題已解決,與 spring 或 oauth 配置完全沒有連接。

采用openjdk Docker image for arm 壞了。 它可以防止發出 https 請求。 甚至以下示例也失敗了:

RestTemplate().getForEntity("https://google.com", String::class.java)

所以解決方案是像這樣在我的 Dockerfile 中交換損壞的基本圖像:

以前的:

FROM adoptopenjdk/openjdk11:armv7l-ubuntu-jdk-11.0.6_10-slim

當前的:

FROM arm32v7/openjdk:11.0.3-slim

假設您在本地和 Kubernetes 中使用完全相同的容器/可執行文件/庫,並且根據您共享的錯誤消息,最可能的原因是您的本地環境和 Kubernetes 環境之間的憑據和/或私鑰不同。

不過,Github 和 Google 的錯誤看起來不同。 第一個錯誤(GitHub)似乎您正在發送一個空令牌。

第二個錯誤(Google)似乎您正在發送與證書不匹配的私鑰。 基於類似的 Java 錯誤

Invalid ECDH ServerKeyExchange signature可以指示密鑰和相應的證書不匹配,並導致握手失敗。 驗證您用於配置的證書頒發機構、證書和密鑰的每個文件的內容。 特別要檢查密鑰和證書是否屬於同一密鑰對。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM