【问题标题】:Android - Oauth2 - Server-side access for your appAndroid - Oauth2 - 应用程序的服务器端访问
【发布时间】:2013-05-28 09:39:56
【问题描述】:

我在我的 Android 应用上实现 Google Play 服务登录并将授权代码传递到我的后端服务器时遇到问题,因此服务器将交换代码以获取访问令牌和刷新令牌。

首先让我写几行已经尝试/阅读的内容:

接下来我编写了简单的 android 应用(基于 Google Play Services 示例身份验证应用)和使用 gdata 的简单 python 代码(使用 web 服务 client_id 和 secret)。

在 android 应用程序上,我首先使用了四个用空格分隔的范围并获得了一个令牌。如果我在我的 python 代码中使用这个令牌,我总是会得到 {'error_message': 'unauthorized_client'}。

然后我尝试将范围更改为这个值,但总是出现无效范围错误。

  • oauth2:server:client_id:server-client-id:api_scope:scope1 scope2
  • audience:server:client_id:server-client-id:api_scope:scope1 scope2
  • oauth2:audience:server:client_id:server-client-id:api_scope:scope1 scope2

对于 server-client-id,我使用了 web 服务器客户端、android 客户端、其他客户端的 client_id

请谁能帮我解决这个问题。

感谢

这是python后端的代码

import gdata
import gdata.gauth


CLIENT_ID = 'client_id'
CLIENT_SECRET = 'secret_id'
SCOPES = ["https://www.google.com/m8/feeds", "https://mail.google.com", "https://www.googleapis.com/auth/userinfo.profile", "https://www.googleapis.com/auth/userinfo.email"]
USER_AGENT = 'my-app'

token = gdata.gauth.OAuth2Token(client_id=CLIENT_ID, client_secret=CLIENT_SECRET, scope=' '.join(SCOPES), user_agent=USER_AGENT)

print "token ", token
print token.generate_authorize_url(redirect_url='urn:ietf:wg:oauth:2.0:oob')

try:
  print token.get_access_token("token")
except Exception, e:
  print e
  print e.__dict__ 

【问题讨论】:

  • 能否请人帮我解决我遇到的这个问题。
  • 您能否列出您在 Android 端拨打的电话的详细信息?这有点令人困惑,因为你说你得到了一个“令牌”和一个“授权码”,这是两个非常不同的东西。
  • 对不起,如果我不够清楚。如果我用四个空格分隔的范围字符串调用 getAuthToken,我会得到一个令牌(假设它是一个访问令牌),然后我可以使用这个令牌从谷歌获取数据(联系人、用户信息)。我无法使用此令牌来获取刷新令牌和访问令牌。但是,如果我想使用 Google Play 服务获取授权代码,使用上面提到的范围组合(包含 Web 服务器的客户端 ID),我总是会从谷歌服务器获得无效的范围响应。希望我对我遇到的问题足够清楚。最佳法律

标签: android google-oauth


【解决方案1】:

您正在检索授权代码,而不是访问令牌。这是两个不同的东西。

授权码can be used in your server side to get an access token。它们不是访问令牌,不能这样使用。

【讨论】:

猜你喜欢
  • 2017-06-04
  • 2018-10-17
  • 1970-01-01
  • 2013-03-23
  • 2011-07-04
  • 1970-01-01
  • 2014-11-18
  • 2012-05-11
  • 1970-01-01
相关资源
最近更新 更多