【问题标题】:Unable to get authenticated user from cloud endpoints无法从云端点获取经过身份验证的用户
【发布时间】:2013-10-08 05:20:47
【问题描述】:

我正在尝试使用endpoints.get_current_user() 从 Python 中的 Cloud Endpoints API 检索经过身份验证的用户。但是 get_current_user 总是返回 None 而不是经过身份验证的用户。我的客户端是一个 Android 应用。

我试过了:

1) 在客户端设置 GoogleAccountCredential:

googleAccountCredential = GoogleAccountCredential.usingAudience(
                getApplicationContext(), 
                webClientId);
        api = new Api.Builder(
                AndroidHttp.newCompatibleTransport(), 
                new GsonFactory(),
                googleAccountCredential)
                        .setRootUrl(apiRootUrl)
                        .setGoogleClientRequestInitializer(requestInitializer)
                        .build();

2) 设置 GoogleAccount 凭据使用的网络客户端 ID:

server:client_id:myid.apps.googleusercontent.com

3) 启动 Google 帐户选择器并在 GoogleAccountCredential 上设置所选帐户:

startActivityForResult(googleAccountCredential.newChooseAccountIntent(), REQUEST_GOOGLE_ACCOUNT_PICKER);

...

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        switch (requestCode) {
          case REQUEST_GOOGLE_ACCOUNT_PICKER:
            if (data != null && data.getExtras() != null) {
              String accountName = data.getExtras().getString(AccountManager.KEY_ACCOUNT_NAME);
              if (accountName != null) {
                googleAccountCredential.setSelectedAccountName(accountName);
              }
            }
            return;
       }
       super.onActivityResult(requestCode, resultCode, data);
    }

4) 在我的 Python API 上设置 allowed_client_ids 和受众:

@endpoints.api(name='api', 
               version='v1', 
               description='My API',
               allowed_client_ids=[config.WEB_CLIENT_ID, 
                                   config.ANDROID_CLIENT_ID, 
                                   endpoints.API_EXPLORER_CLIENT_ID],
               audiences=[config.WEB_CLIENT_ID])
class MyApi(remote.Service):
...

我能够将我的 Android 应用程序连接到我的开发 App Engine 服务器,而不会出现任何错误。我错过了什么?

【问题讨论】:

    标签: android google-app-engine google-cloud-endpoints


    【解决方案1】:

    发生这种情况是因为他们没有安装 pycrypto 库。它需要在 app.xml 中安装和引用。见Cloud endpoints authentication from android: Oauth framework user didn't match oauth token user

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-04-07
      • 1970-01-01
      • 1970-01-01
      • 2018-11-26
      • 1970-01-01
      • 2022-08-14
      • 1970-01-01
      • 2017-08-02
      相关资源
      最近更新 更多