How to control the login flow in ADAL AuthenticationContext?

a 夏天 提交于 2019-12-23 13:06:49

问题


Using the ADAL library for getting a token for WAAD i would like to know how I can get more control over the login flow.

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"));

The user is prompted to login. For me it's via Live Id, for my customer's computer it's via an organizational account, and there is no way to switch between them. It seems to be controlled by how/what current sessions the computer might have running already logged into azure.

Can I do anything in the AcquireToken call to control this? It would be best if I could trigger the normal flow when people log into Azure where they get to select if its a live id or a organizational login.

I have tried this:

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");

with no luck.


回答1:


I found some magic tricks that seems to give some more control.

// 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);
}


来源:https://stackoverflow.com/questions/21689686/how-to-control-the-login-flow-in-adal-authenticationcontext

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!