Android 验证GoogleAuthUtil.getToken()Google+;在服务器上
第一次使用Google+API。我有一个带有web和Android客户端的应用程序,它使用G+进行身份验证。Web客户端工作得很好。我在GoogleAPI控制台中设置了一个“web应用程序的客户机ID”,我使用它通过javascript客户机获取令牌 javascript客户端使用以下按钮(基本上是从Google演示应用程序一字不差地获取): 到目前为止还不错。令牌按预期进行验证 现在来看android应用程序。。。我为同一个项目设置了“android应用程序的客户端ID”,调试指纹由以下生成: keytool-exportcert-alias androiddebugkey-keystore debug.keystore-list-v 客户端id名称的包与我的Android清单中的内容匹配 我正在使用GoogleAuthUtil在我的Android应用程序中生成令牌:Android 验证GoogleAuthUtil.getToken()Google+;在服务器上,android,api,google-plus,google-authentication,Android,Api,Google Plus,Google Authentication,第一次使用Google+API。我有一个带有web和Android客户端的应用程序,它使用G+进行身份验证。Web客户端工作得很好。我在GoogleAPI控制台中设置了一个“web应用程序的客户机ID”,我使用它通过javascript客户机获取令牌 javascript客户端使用以下按钮(基本上是从Google演示应用程序一字不差地获取): 到目前为止还不错。令牌按预期进行验证 现在来看android应用程序。。。我为同一个项目设置了“android应用程序的客户端ID”,调试指纹由以下生成:
String token =
GoogleAuthUtil.getToken(
this,
"selected@email.address",
"oauth2:server:client_id:<client_id>:" +
"api_scope:https://www.googleapis.com/auth/plus.login");
我已经验证了到达服务器的令牌与在应用程序中获取的令牌相同(没有多余的空格等)
知道我做错了什么吗?谢谢你的建议 我最后做的是: 调用GoogleAuthUtil而不是以下作用域时:
oauth2:server:client\u id::api\u作用域:https://www.googleapis.com/auth/plus.login
我用过:
受众:服务器:客户端\u id:
其中client_id是web客户端id
这会产生更长的令牌。您可以通过以下方式解密/验证此令牌:
https://www.googleapis.com/oauth2/v1/tokeninfo?id_token=
请注意,查询参数键是id_令牌,而不是access_令牌
服务器响应如下:
{
“发卡机构”:“accounts.google.com”,
“发给”:
希望这能节省一些时间
url = ('https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=%s' % token)
h = httplib2.Http()
result = json.loads(h.request(url, 'GET')[1])
String token =
GoogleAuthUtil.getToken(
this,
"selected@email.address",
"oauth2:server:client_id:<client_id>:" +
"api_scope:https://www.googleapis.com/auth/plus.login");
{u'error_description': u'Invalid Value', u'debug_info': u'code: INVALID_VALUE
http status: 400
arguments: [invalid_token]
cause: com.google.security.lso.protocol.oauth2.common.OAuth2ErrorException:\
invalid_token at
com.google.security.lso.grant.token.TokenManager.getTokenInfo(TokenManager.java:603) at
com.google.security.lso.apiary.tokeninfo.TokenInfoAction.execute(TokenInfoAction.java:92)
oauth2:server:client_id:<client_id>:api_scope:https://www.googleapis.com/auth/plus.login
audience:server:client_id:<client_id>
https://www.googleapis.com/oauth2/v1/tokeninfo?id_token=<token>
{
"issuer": "accounts.google.com",
"issued_to": "<android_client_id>",
"audience": "<web_client_id>",
"user_id": "<some_long_integer>",
"expires_in": 3354,
"issued_at": 1406474776,
"email": "<email address passed to GaiaAuthUtil>",
"verified_email": true
}