首页 文章

无法从 Cloud endpoints 获取经过身份验证的用户

提问于
浏览
0

我正在尝试使用 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凭据使用的Web客户端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和 Spectator :

@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服务器,没有任何错误 . 我错过了什么?

1 回答

相关问题