0
我已按照these instructions在我的后端服务器上使用Android登录。google/apiclient:签名验证失败
Android的登录作品,我发现了一个ID令牌与我的服务器的客户端ID:
// Configure sign-in to request the user's ID, email address, and basic
// profile. ID and basic profile are included in DEFAULT_SIGN_IN.
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken(getString(R.string.server_client_id))
.build();
// Build a GoogleApiClient with access to the Google Sign-In API and the
// options specified by gso.
mGoogleApiClient = new GoogleApiClient.Builder(this)
.enableAutoManage(this /* FragmentActivity */, this /* OnConnectionFailedListener */)
.addApi(Auth.GOOGLE_SIGN_IN_API, gso)
.build();
mGoogleSignIn.setSize(SignInButton.SIZE_STANDARD);
mGoogleSignIn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
startActivityForResult(signInIntent, REQUEST_CODE_SIGN_IN);
}
});
此令牌发送到我的后端服务器作为POST请求(代码无关:它作品)。
然后,服务器(一个symfony的后端)使用google/apiclient
到再次认证所述用户,以便验证用户ID和在后端数据库获取的用户信息:
// Get token from user
$id_token = $request->get('id_token');
// Validate token
try {
$options = [
'client_id' => $this->container->getParameter('google_app_id')
];
$client = new \Google_Client($options);
$payload = $client->verifyIdToken($id_token);
if ($payload) {
$user = $this->getDoctrine()
->getRepository(User::class)
->findOneBy(['googleId' => $payload['sub']]);
if ($user != null) {
$data = [
'client_id' => $user->getClient()->getClientId(),
'client_secret' => $user->getClient()->getSecret(),
];
} else {
$data = [
'error' => 'Unknown user',
'message' => 'Please create an account first',
];
}
} else {
$data = [
'error' => 'Invalid token',
];
}
} catch (\Exception $e) {
$data = [
'error' => 'Invalid token',
'details' => $e->getMessage(),
];
}
异常上升,该消息是Signature Verification Failed
。
经过一些在线研究,我找不到此消息的原因。这是什么造成的?在后端使用相同的代码工作,我只是改变了Android的一些东西,但与Google登录无关。
难以分辨您提供的信息,您可以做一些事情,如更新OpenSSL并检查是否配置时区 – Vamsi
我知道我没有提供任何信息。 OpenSSL和日期是正确的,但这是一个非常好的主意。 –