简体   繁体   中英

Azure app service Google authentication

I have successfully create a simple android application that successfully logs into Google using an Azure app service.

ListenableFuture<MobileServiceUser> mLogin = mClient.login(MobileServiceAuthenticationProvider.Google);

    Futures.addCallback(mLogin, new FutureCallback<MobileServiceUser>() {
        @Override
        public void onFailure(Throwable exc) {
            createAndShowDialog(exc.toString(), "Error");
        }
        @Override
        public void onSuccess(MobileServiceUser user) {
            createAndShowDialog(String.format(
                    "You are now logged in - %1$2s",
                    user.getUserId()), "Success");

        }
    });

At this point I have successfully logged in and have received an Auth token and a UserID.

My question is no where online can I find any way get extra profile information for the logged in user. I have seen some suggestions about using ServiceUser rather than MobileServiceUser but don't seem to have any luck making a ServiceUser object. That can be found here. How to retrieve user's additional information from Azure Mobile/App Services?

Does anyone know of a solution?

Thanks in advance!

If you are using Easy Authentication as described here , then you can simple append the endpoint /.auth/me to the URL. For example:

Login Endpoint : https://easyauthkaushal.azurewebsites.net/.auth/login/google

User Details : https://easyauthkaushal.azurewebsites.net/.auth/me

Also refer to Google documentation on working with claims and scopes. See this: OAuth 2.0 Scopes for Google APIs

The only way to get user information besides the auth token and the User Id your service assigned the user is to go the client directed OAuth route. Here is the MSDN article about it. Basically, you need to make the OAuth call yourself to Google, they will give you access to everything your app is authorized to have, including name, and you need to pass the token you get from them to your mobile/app service.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM