Azure移动应用程序 - Android身份验证获取其他信息

时间:2016-08-16 22:08:19

标签: android azure authentication azure-mobile-services

我目前对如何继续使用我的应用感到茫然。 我目前在这里按照教程进行身份验证,一切都顺利进行。Azure Mobile Apps Authentication

我不知道如何使用此过程后存储的ID和/或令牌来获取用户电子邮件或其个人资料照片的基本个人资料信息。 从我在网上看到的,这只是一个azureId,它不存储我将用于google + apis的谷歌个人资料ID。

有没有人有参考资料显示新手程序员如何获取使用google api所需的电子邮件地址或userId。 我能找到的唯一参考是2014年的博客文章。当然必须有一个更简单的方法。还有一个专门针对移动应用程序而不是移动服务而编写的应用程序。 Blog post describing how to expand on authentication with google on mobile services which is no use

这是我的流程

// 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();
            }
        });
    }

1 个答案:

答案 0 :(得分:1)

您发布的第一个文档链接有答案。来自https://azure.microsoft.com/en-us/documentation/articles/app-service-authentication-overview/#working-with-user-identities-in-your-application

  

以任何语言或框架编写的代码都可以从这些标头中获取所需的信息。对于ASP.NET 4.6应用程序,ClaimsPrincipal会自动设置适当的值。

     

您的应用程序还可以通过应用程序的 /.auth / me 端点上的HTTP GET获取其他用户详细信息。 请求中包含的有效令牌将返回JSON有效内容,其中包含有关正在使用的提供程序,基础提供程序令牌和其他一些用户信息的详细信息。 Mobile Apps服务器SDK提供了帮助方法来处理此数据。有关详情,请参阅How to use the Azure Mobile Apps Node.js SDKWork with the .NET backend server SDK for Azure Mobile Apps

总而言之,根据您使用的语言,您有不同的选择,但最常见的跨平台选项是向移动应用发送经过身份验证的请求 /.auth/me 端点。您将获得一个JSON对象,其中包含大量用户声明(名称,提供者特定ID,电子邮件等)。