4

我目前正在使用 google sign 对我的应用程序的用户进行身份验证,但在刷新 id_token 后出现问题。我设置了以下变量。一个用于 iOS 客户端,一个用于服务器。这是以下 AWS 示例。我正在使用 AWS 访问服务器,因此需要一个客户端 ID 和 Web 应用程序 ID。

static let GOOGLE_CLIENT_ID = "xxxxxxxxxxxxxxxxxxxxxxxxxxxx-xxxxxxxxxxxxxxx7dde.apps.googleusercontent.com"

// Backend web application client ID
static let GOOGLE_WEB_APPLICATION_ID = "xxxxxxxxxxxxxxxxxxxxxxxxxxxx-xxxxxxxxxxxxxxx65ap.apps.googleusercontent.com"

当我第一次登录应用程序时,它按预期工作。我得到一个 id 令牌,它具有以下内容:

{
  "iss": "https://accounts.google.com",
  "at_h ash": "xxxxxxxxxxxxxxxxxxxxxx",
  "aud": "xxxxxxxxxxxxxxxxxxxxxxxxxxxx-xxxxxxxxxxxxxxx65ap.apps.googleusercontent.com",
  "sub": "xxxxxxxxxxxxxxxxxxxxxx",
  "email_verified": true,
  "azp": "xxxxxxxxxxxxxxxxxxxxxxxxxxxx-xxxxxxxxxxxxxxx7dde.apps.googleusercontent.com",
  "email": "2222MyNewEmailIsHere@gmail.com",
  "iat": 1475747692,
  "exp": 1475751292
}

您可以看到“aud”与 GOOGLE_WEB_APPLICATION_ID 匹配,“azp”与 GOOGLE_CLIENT_ID 匹配。

但是,如果我像这样执行 refreshTokensWithHandler :

GIDSignIn.sharedInstance().currentUser.authentication.refreshTokensWithHandler { (GIDAuthentication, error) in

                self.googleAuth = GIDAuthentication;
                self.completeGoogleLogin()
}

我的回复有问题。id 令牌正在正确刷新,因此有一个新的 id 令牌。但是,“aud”似乎被客户端 ID 覆盖。无论令牌是否过期,都会发生这种情况。

{
  "iss": "https://accounts.google.com",
  "at_h ash": "xxxxxxxxxxxxxxxxxxxxxx",
  "aud": "xxxxxxxxxxxxxxxxxxxxxxxxxxxx-xxxxxxxxxxxxxxx7dde.apps.googleusercontent.com"",
  "sub": "xxxxxxxxxxxxxxxxxxxxxx",
  "email_verified": true,
  "azp": "xxxxxxxxxxxxxxxxxxxxxxxxxxxx-xxxxxxxxxxxxxxx7dde.apps.googleusercontent.com",
  "email": "2222MyNewEmailIsHere@gmail.com",
  "iat": 1475747692,
  "exp": 1475751292
}

如您所见,第二个响应中的“aud”和“azp”是相同的。然后当我去向服务器发出请求时,它抱怨无法验证令牌。

我想知道是否有其他人经历过这种情况?这似乎是 GIDSignIn 的问题。

4

0 回答 0