Search code examples
identityserver4microsoft-identity-web

How to provide login_hint to microsoft-identity-web


I'm using microsoft-identity-web (https://github.com/AzureAD/microsoft-identity-web) in combination with IdentityServer4 to enable signing into my app through identity server4 with an AAD account. Everything is just working fine.

I would like to know if it is possible to provide a login_hint to microsoft-identity-web such that the name field of the sign-in form at Microsoft can be pre-populated.


Solution

  • It turns out that you can pass a user name to the external authentication flow by providing a login hint to the authentication properties, as displayed below:

    // start challenge and roundtrip the return URL and scheme 
    var props = new AuthenticationProperties
    {
       RedirectUri = redirectUrl,
       Items = {{"provider", provider.AuthenticationScheme}},
       Parameters = {{ "login_hint", <user name to display in login screen>}}
    };
    return Challenge(props, provider.AuthenticationScheme);
    

    See e.g. http://docs.identityserver.io/en/latest/topics/signin_external_providers.html for information about how signing using external identity providers such as Microsoft.