簡體   English   中英

如何從Azure Active Directory檢索用戶信息

[英]How to retrieve user information from Azure Active Directory

我對Xamarin和Azure Active Directory有點陌生,所以請耐心等待。 我在嘗試從Azure Active Directory檢索用戶信息(名字,姓氏和圖片)時遇到麻煩。 請注意,Azure Active Directory中的電子郵件是Google帳戶。

每次嘗試檢索它時,我只會收到一個錯誤,它要求我對AGAIN進行身份驗證才能檢索我想要的內容。 這是我的代碼:

 // 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放入什么一無所知。

您要做的步驟是:

  1. 使用Azure進行身份驗證(您將獲得一個包含令牌的User對象)
  2. 將令牌放置在您提出的每個請求上。 這樣,您便可以與該特定用戶進行身份驗證。

檢出: https : //blog.xamarin.com/authenticate-xamarin-mobile-apps-using-azure-active-directory/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM