移动应用程序GetIdentityAsync没有值 [英] Mobile App GetIdentityAsync no value

查看:68
本文介绍了移动应用程序GetIdentityAsync没有值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从Azure Services Mobile App(API自定义控制器)获得了此代码.结果总是相同的"1:1".我测试了除AD之外的所有身份提供者,google,facebook,twitter和Microsoft帐户.我认为问题是对GetIdentityAsync的调用.谁能帮我?谢谢

I have this code from Azure Services Mobile App, API custom controller. The result always the same "1:1". I test with all identity providers, google, facebook, twitter, and Microsoft Account, except AD. I think the problem is the call to GetIdentityAsync. Can anyone help me? Thanks

    [HttpGet]
    public async Task<string> GetIdentityInfo()
    {
        var user = (MobileAppUser)this.User;            

        string str = "";
        string Provider = "YES", UserId = "NO";
        try
        {
            if (user != null)
            {
                Provider = "1"; UserId = "1";
                var microsoftCredentials = await user.GetIdentityAsync<MicrosoftAccountCredentials>();
                if (microsoftCredentials != null && microsoftCredentials.Claims != null)
                {
                    Provider = "MICROSOFT";
                    UserId = microsoftCredentials.UserId;
                }

                Provider = "2"; UserId = "2";
                var googleCredentials = await user.GetIdentityAsync<GoogleCredentials>();
                if (googleCredentials != null && googleCredentials.Claims != null)
                {
                    Provider = "GOOGLE";
                    UserId = googleCredentials.UserId;
                }

                Provider = "3"; UserId = "3";
                var facebookCredentials = await user.GetIdentityAsync<FacebookCredentials>();
                if (facebookCredentials != null && facebookCredentials.Claims != null)
                {
                    Provider = "FACEBOOK";
                    UserId = facebookCredentials.UserId;
                }

                Provider = "4"; UserId = "4";
                var twitterCredentials = await user.GetIdentityAsync<TwitterCredentials>();
                if (twitterCredentials != null && twitterCredentials.Claims != null)
                {
                    Provider = "TWITTER";
                    UserId = twitterCredentials.UserId;
                }
            }
            else
            {
                Provider = "NONE"; UserId = "NULL";
            }
        }
        catch (Exception ex)
        {
            str = "ERROR";
        }
        finally
        {
            str = Provider + ":" + UserId;
        }

        return str;
    }

推荐答案

我们获得了Microsoft支持工程师Adrian Fernandez Garcia的支持,并发送了可以正常运行的示例.唯一的区别是必须在应用程序属性"中的azure门户中的移动应用程序中手动创建EMA_RuntimeUrl,并将其分配给网关地址.

We receive support from Microsoft Support Engineer Adrian Fernandez Garcia, and send an example that worked OK. The unique difference was that EMA_RuntimeUrl must be created manually in mobile app in azure portal in Application Properties, and assigned to Gateway address.

实际上,该值是自动创建的,无需手动创建.

Actually this value is created automatically and don't have to create it manually.

这给了我们错误URIFormat NULL value.

现在一切正常.

感谢Microsoft的支持.

Thanks to Microsoft for the support.

这篇关于移动应用程序GetIdentityAsync没有值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆