【问题标题】:How to retrieve user information from Azure Active Directory如何从 Azure Active Directory 检索用户信息
【发布时间】:2016-11-07 04:29:51
【问题描述】:

我对 Xamarin 和 Azure Active Directory 有点陌生,所以请多多包涵。我在尝试从 Azure Active Directory 检索用户信息(名字、姓氏和图片)时遇到问题。请注意,Azure Active Directory 中的电子邮件是 Google 帐户。

每次我尝试检索它时,我只会收到一个错误,并且它需要我再次进行身份验证才能检索我想要的内容。这是我的代码:

 // Use MobileServices Login to authenticate user
 private async Task<bool> AuthenticateUsingMobileServices(Activity activity)
 {
      var success = false;
      try
      {
           // Sign in with Active Directory
           MobileUser = await MobileService.LoginAsync(activity, 
                MobileServiceAuthenticationProvider.WindowsAzureActiveDirectory);
           System.Diagnostics.Debug.WriteLine("you are now logged in - Logged in!");
           System.Diagnostics.Debug.WriteLine([insert user name here]);
           success = true;
      }
      catch (Exception ex)
      {
           System.Diagnostics.Debug.WriteLine("Authentication failed " + ex.ToString());
      }
}

除了我已经定义的 ResourceUri 和 ClientId 之外,我还尝试添加它:

 AuthenticationContext authContext = new AuthenticationContext(CommonAuthority);
 AuthResult = await authContext.AcquireTokenAsync(ResourceUri, ClientId, UserCredential);

但我不知道应该为 ClientAssertion 或 UserAssertion 放什么。

【问题讨论】:

    标签: c# android azure xamarin xamarin.android


    【解决方案1】:

    你要做的步骤是:

    1. 使用 Azure 进行身份验证(您将获得一个包含令牌的用户对象)
    2. 在您发出的每个请求上放置令牌。这样您就可以向该特定用户进行身份验证。

    查看:https://blog.xamarin.com/authenticate-xamarin-mobile-apps-using-azure-active-directory/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-09-17
      • 1970-01-01
      • 2010-10-02
      • 1970-01-01
      • 2020-03-13
      • 1970-01-01
      • 2017-04-07
      • 2019-06-18
      相关资源
      最近更新 更多