gpt4 book ai didi

android - 谷歌/apiclient : Signature Verification Failed

转载 作者:行者123 更新时间:2023-11-30 00:24:20 26 4
gpt4 key购买 nike

我关注了these instructions在我的后端服务器上使用 Android 登录。

Android 登录有效,我得到一个带有我的服务器客户端 ID 的 ID token :

// 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);
}
});

此 token 作为 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 Sign In 无关。

最佳答案

今天早上我用完全相同的代码再次尝试,结果非常有效。我猜这是 Google 方面的暂时性故障(没想到!)。

我想更多地了解错误消息而不是我的代码中的错误(没有任何错误!)所以如果有人有更清晰的解释我会接受他们的回答。

关于android - 谷歌/apiclient : Signature Verification Failed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45664811/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com