2014-10-31 130 views
8

任何使用Azure AD圖形客戶端的新2.0版本的人?Azure Active Directory圖形客戶端2.0

昨天我開始玩弄它,但無法啓動它。 GraphConnection類被標記爲廢棄,並替換爲ActiveDirectoryClient。此外,突然之間,所有Office 365都只是想將我的試用限制在沒有O365的Azure Active Directory中。很難找到文檔,至少在您不想使用O365和O365 API工具時很難找到。 GitHub上的AD樣本似乎也被更新,但代碼仍在使用GraphConnection類。去搞清楚。所以下面的代碼使用現在

public async Task<ActionResult> Index() 
     { 
      List<Exception> exceptions = new List<Exception>(); 
      ProfileViewModel model = new ProfileViewModel(); 
      string userObjectID = ClaimsPrincipal.Current.FindFirst("http://schemas.microsoft.com/identity/claims/objectidentifier").Value; 
      AuthenticationContext authContext = new AuthenticationContext(SecurityConfiguration.Authority, new NaiveSessionCache(userObjectID)); 
      ClientCredential credential = new ClientCredential(SecurityConfiguration.ClientId, SecurityConfiguration.AppKey); 

      try 
      { 
       var ServiceUri = new Uri(SecurityConfiguration.GraphUrl); 
       ActiveDirectoryClient client = new ActiveDirectoryClient(ServiceUri, async() => 
       { 
        var result = await authContext.AcquireTokenSilentAsync(SecurityConfiguration.GraphUrl, credential, new UserIdentifier(userObjectID, UserIdentifierType.UniqueId)); 

        return result.AccessToken; 
       }); 
       try 
       { 

        var users = await client.Users.ExecuteAsync(); 

        var user = await client.Users[userObjectID].ExecuteAsync(); 


       } 
       catch (Exception exc) 
       { 
        exceptions.Add(exc); 
       } 


      } 
      catch (AdalSilentTokenAcquisitionException exc) 
      { 
       exceptions.Add(exc); 

      } 
      ViewBag.Exceptions = exceptions; 
      return View(model); 
     } 

client.Users.ExecuteAsync()拋出異常

The response payload is a not a valid response payload. Please make sure that the top level element is a valid Atom or JSON element or belongs to 'http://schemas.microsoft.com/ado/2007/08/dataservices' namespace. 

client.Users[userObjectID].ExecuteAsync()使用的ActiveDirectory客戶端尚未

不多樣品/指導拋出System.Reflection.TargetInvocationException與Innerexpection

Expected a relative URL path without query or fragment. 
Parameter name: entitySetName 

UPDATE 2/11

幽靈般的解決方案:無需更改一行代碼'client.Users.ExecuteAsync()'按預期工作。我的想法是,Msft的人改變了API的一些東西,以便響應有效載荷現在是正確的。他們可以提到這一點。

要使用獲得用戶信息V2.0代碼下面的伎倆

變種userFetcher = client.Users.Where(U => u.ObjectId == userObjectID); var user = await userFetcher.ExecuteAsync();

如果使用剃刀顯示當試圖去通過收集諸如此類AssignedPlans

The type 'System.Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. 

分辨率以你的web.config,以改變編譯設置,你可能會得到剃鬚刀例外用戶的內容在http://www.lyalin.com/2014/04/25/the-type-system-object-is-defined-in-an-assembly-that-is-not-reference-mvc-pcl-issue/

<compilation debug="true" targetFramework="4.5" > 
     <assemblies> 
     <add assembly="System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" /> 
     </assemblies> 
    </compilation> 
+0

我們發現AAD非常,非常沮喪與最近的工作。我們目前正在遇到各種問題,特別是ZUMO方面的問題,並在一些博客上找到解決方案,所以在官方文檔中沒有提到這些問題。如果你沒有準確地跟隨MS的教程,那你就是一場瘋狂的追逐。 – 2014-11-12 02:50:26

回答

0

列出按ID檢索用戶的實體,而不是:

var userFetcher = client.Users.Where(u => u.ObjectId == userObjectID); 
var user = await userFetcher.ExecuteAsync(); 

你可以用getByObjectId直接:

var user = await client.Users.GetByObjectId(userObjectID).ExecuteAsync(); 
相關問題