Can I use Google Plus sign in to authenticate my OAuth methods in app engine?

こ雲淡風輕ζ 提交于 2019-12-24 12:21:03

问题


I successfully implemented Google Account sign in using the tutorial here for Android:

https://developers.google.com/appengine/docs/java/endpoints/getstarted/clients/android/add_auth_code

This allows my app to successfully use endpoints in app engine while authenticated.

However now I'd like to perform some Google Plus functionality, ie: obtain some info about the user. I followed the code for the G+ signin as below:

https://developers.google.com/+/mobile/android/getting-started#step_4_initialize_the_googleapiclient

What I'd like to know is if these 2 methods can somehow be merged? I feel like I'm asking the user to sign in twice with his Google account... Is there anyway the GoogleApiClient of G+ can be used to generate the credentials needed for the Google Endpoints authentication?


回答1:


Once signed in using Google+, you're almost good to go to talk to your Backend API. Something like this was what I did:

   @Override
   public void onConnected(Bundle bundle) {

    // Update the user interface to reflect that the user is signed in.
    mSignInProgress = STATE_DEFAULT;

    if (BuildConfig.DEBUG) {
        Log.i(LOG_TAG, "Signed in");
    }
    final String accountName = Plus.AccountApi.getAccountName(mGoogleApiClient);
    credential.setSelectedAccountName(accountName); // private GoogleAccountCredential credential;


    // call your GAE stuff


    }


来源:https://stackoverflow.com/questions/25656511/can-i-use-google-plus-sign-in-to-authenticate-my-oauth-methods-in-app-engine

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!