如何重新验证 google 以及从 android 生成的 REST 端的访问令牌

How to revalidate google plus access token at REST side generated from android

我有一个 android 应用程序,它发送 google 加上通过社交登录生成的 api 访问令牌到基于 php 的 REST 服务。然后我需要它在 php 重新验证。现在我有不同的 android 客户端凭据和单个 google 应用程序的网站。

PHP 边码就像

            $client = new Google_Client();
            $client->setApplicationName($config->gAppName);
            $client->setClientId($config->gClientId);
            $client->setClientSecret($config->gClientSecret);
            //$client->setRedirectUri($config->gRequestUri);

            $plus = new Google_Service_Plus($client);

            $attributes = $client->verifyIdToken($data['accessToken'], $config->gClientId)->getAttributes();
            $socialUserId = $attributes["payload"]["sub"];

rest 端请求给出错误令牌中的段数错误。如何解决?

更新:通过 php 代码检查身份验证后,我发现访问令牌应该是 JSON 对象而不是字符串。喜欢

{"access_token":"[ACCESS_TOKEN_STRING]","token_type":"Bearer","expires_in":[TIMESTAMP],"id_token":"ID_TOKEN","created":[TIMESTAMP]} 

还是不知道,应该怎么生成。

查阅在线文档后,我得到了另一种解决方案。我需要使用 API url

https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=[ACCESS_TOKEN]

此 url 将验证访问令牌并提供用户 ID,以便与来自 android 应用的用户 ID 重新匹配。