0
votes

I'm trying to retrieve an authenticated user from a Cloud Endpoints API in Python using endpoints.get_current_user(). But get_current_user always returns None instead of an authenticated user. My client is an Android app.

I have tried:

1) Setting the GoogleAccountCredential in the client:

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

2) Setting the web client id used by the GoogleAccount credential:

server:client_id:myid.apps.googleusercontent.com

3) Starting the Google account selector and setting the selected account on the 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) Setting allowed_client_ids and audiences on my Python API:

@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):
...

I'm able to connect my Android app to my dev App Engine server without any errors. What am I missing?

1

1 Answers

0
votes

This was happening because they pycrypto library was not installed. It needs to be installed and referenced in app.xml. See Cloud endpoints authentication from android: Oauth framework user didn't match oauth token user