Spring 安全性 - Google OAuth 2.0 - UnknownHostException www.googleapis.com

Spring Security - Google OAuth 2.0 - UnknownHostException www.googleapis.com

我已经根据本教程实现了 Google oauth 登录:https://www.callicoder.com/spring-boot-security-oauth2-social-login-part-1/

当应用程序在本地 运行 时,它可以正常工作。但是,在 GKE 上部署它之后,我无法登录 - 流程失败并出现以下错误:

error: [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": www.googleapis.com; nested exception is java.net.UnknownHostException: www.googleapis.com

来自OAuth2AccessTokenResponseClient

正如我之前所说,在本地主机上 运行 时它工作正常,但我无法调试它。 该应用程序使用静态 IP 通过 Ingress 进行部署。我最近将该 IP 分配给了我的域。域已在 Google API Authorised redirect URIs

中注册

Google API 使用 OAuth 2.0 协议进行身份验证和授权。 Google 支持常见的 OAuth 2.0 场景,例如用于 Web 服务器、已安装和客户端应用程序的场景。请看看这个 link.

我们可以按照以下步骤获取 obtaining OAuth 2.0 访问令牌。 第 1 步:生成代码验证器和挑战 第 2 步:向 Google 的 OAuth 2.0 服务器发送请求 第 3 步:Google 提示用户同意 第 4 步:处理 OAuth 2.0 服务器响应 第 5 步:交换刷新和访问令牌的授权码

问题是 kube-dns pods 没有起床。我设置了一个抢占式集群并向它的唯一节点池添加了一个污点。这阻止了 kube-dns 启动:

Normal   NotTriggerScaleUp  61s (x22798 over 2d18h)  cluster-autoscaler  pod didn't trigger scale-up (it wouldn't fit if a new node is added): 1 node(s) had taints that the pod didn't tolerate
Warning  FailedScheduling   44s (x141 over 26h)      default-scheduler   0/1 nodes are available: 1 node(s) had taints that the pod didn't tolerate.

删除污点主机名后得到解决