首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >google/apiclient:签名验证失败

google/apiclient:签名验证失败
EN

Stack Overflow用户
提问于 2017-08-14 04:51:56
回答 1查看 327关注 0票数 1

我跟随these instructions在我的后端服务器上使用Android登录。

Android登录起作用了,我得到了一个带有我的服务器客户端id的ID令牌:

代码语言:javascript
复制
// 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并在后端数据库中获取用户信息:

代码语言:javascript
复制
// 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端的一些东西,但与谷歌登录无关。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-08-14 21:28:13

今天早上我用完全相同的代码再试了一次,它的效果很好。我猜这是Google方面的一个暂时的失败(没想到!)

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45664811

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档