Thomas Murphy
Thomas Murphy

Reputation: 41

Azure Mobile Apps - Android Authentication getting additional information

I am currently at a loss on how to proceed with my app. I currently authenticate following the tutorial here and everything works swimmingly.Azure Mobile Apps Authentication

Where I am at a loss is how to use the id and/or token that is stored following this process to obtain basic profile information say a users email or their profile photo. From what I have read online this is merely a azureId that stored not the google profile ID which I would use with the google+apis.

Has anyone got a reference that shows a novice programmer how to get the email address or userId required to use the google api. The only reference I can find is a blog post from 2014. Surely there must be an easier way. And one specifically written to work on Mobile apps as opposed to mobile services. Blog post describing how to expand on authentication with google on mobile services which is no use

Here is my process

// We first try to load a token cache if one exists.
    Log.v(TAG, "Click"+USERIDPREF );
    if (loadUserTokenCache(mClient))
    {
        Log.v(TAG, "table" +mClient.getCurrentUser().toString());
        createTable();
        returnHome();
    }
    // If we failed to load a token cache, login and create a token cache
    else
    {
        // Login using the Google provider.
        final ListenableFuture<MobileServiceUser> mLogin = mClient.login(MobileServiceAuthenticationProvider.Google);
        Futures.addCallback(mLogin, new FutureCallback<MobileServiceUser>() {
            @Override
            public void onFailure(Throwable exc) {
                Log.v(TAG, "Login On fail " +exc.getMessage() );
            }
            @Override
            public void onSuccess(MobileServiceUser user) {
                Log.v(TAG, "On Success" );
                createTable();
                cacheUserToken(mClient.getCurrentUser());
                Log.v(TAG, "On Success" + mClient.getCurrentUser() );
                returnHome();
            }
        });
    }

Upvotes: 1

Views: 170

Answers (1)

Chris Gillum
Chris Gillum

Reputation: 15042

The first documentation link you posted has the answer. From https://azure.microsoft.com/en-us/documentation/articles/app-service-authentication-overview/#working-with-user-identities-in-your-application:

Code that is written in any language or framework can get the information that it needs from these headers. For ASP.NET 4.6 apps, the ClaimsPrincipal is automatically set with the appropriate values.

Your application can also obtain additional user details through an HTTP GET on the /.auth/me endpoint of your application. A valid token that's included with the request will return a JSON payload with details about the provider that's being used, the underlying provider token, and some other user information. The Mobile Apps server SDKs provide helper methods to work with this data. For more information, see How to use the Azure Mobile Apps Node.js SDK, and Work with the .NET backend server SDK for Azure Mobile Apps.

So to summarize, you have different options depending on which language you use, but the most cross-platform option is to send an authenticated request to your mobile app's /.auth/me endpoint. You'll get back a JSON object which contains a bunch of user claims (name, provider-specific ID, email, etc.).

Upvotes: 1

Related Questions