2014-02-10 20 views
4

使用ADAL庫獲取WAAD令牌我想知道如何獲得對登錄流程的更多控制。如何控制ADAL AuthenticationContext中的登錄流?

var ac = new AuthenticationContext("https://login.windows.net/" + ActiveDirectoryTenantId); 
AuthenticationInfo = ac.AcquireToken(
         resource: "https://management.core.windows.net/", 
         clientId: "1950a258-227b-4e31-a9cf-717495945fc2", 
         redirectUri: new Uri("urn:ietf:wg:oauth:2.0:oob")); 

提示用戶登錄。對於我來說,它是通過Live ID進行的,因爲我的客戶的計算機是通過組織帳戶進行的,無法在它們之間切換。它似乎受到計算機可能運行的當前會話的方式/已經登錄到天藍色的控制。

我可以在AcquireToken調用中做任何事情來控制它嗎? 如果我可以在人們登錄到Azure時觸發正常流程,那麼他們最好選擇是否存在活動ID或組織登錄。

我已經試過這樣:

ac.AcquireToken("https://management.core.windows.net/", 
        "1950a258-227b-4e31-a9cf-717495945fc2", 
        new Uri("urn:ietf:wg:oauth:2.0:oob"), PromptBehavior.Always,"wtrealm=urn:federation:MicrosoftOnline"); 

沒有運氣。

回答

1

我發現了一些魔術,似乎給了一些更多的控制。

// ID for site to pass to enable EBD (email-based differentiation) 
// This gets passed in the call to get the azure branding on the 
// login window. Also adding popup flag to handle overly large login windows. 
internal const string EnableEbdMagicCookie = "site_id=501358&display=popup"; 

private void ClearCookies() 
{ 
    NativeMethods.InternetSetOption(IntPtr.Zero, NativeMethods.INTERNET_OPTION_END_BROWSER_SESSION, IntPtr.Zero, 0); 
} 

private static class NativeMethods 
{ 
    internal const int INTERNET_OPTION_END_BROWSER_SESSION = 42; 

    [DllImport("wininet.dll", SetLastError = true)] 
    internal static extern bool InternetSetOption(IntPtr hInternet, int dwOption, IntPtr lpBuffer, 
     int lpdwBufferLength); 
} 
+0

這需要嵌入到ADAL方法中......本地客戶端有時需要更改登錄的用戶而無需重新啓動! –