Search code examples
c#azure-active-directoryopenidopenid-connect

Use login_hint with OpenID


I am trying to add the login_hint to the OpenID sign-in request for Azure AD authentication.

It is not working for me, to add login_hint as a property:

var properties = new AuthenticationProperties();

properties.RedirectUri = "someCallbackUrl";

properties.Dictionary.Add("login_hint ", "SomeUsername");

AuthenticationManager.Challenge(properties, OpenIdConnectAuthenticationDefaults.AuthenticationType);

Adding the login_hint manually to the query string ...&login_hint=SomeUsername at least proves to me, that such functionality exists :-)

I understand that if I were to use GoogleOAuth2AuthenticationProvider that I would have to override itself like so. Is something similar needed for the approach that I am trying to take?


Solution

  • It turns out that I had to add the RedirectToIdentityProvider to app.UseOpenIdConnectAuthentication:

    Notifications = new OpenIdConnectAuthenticationNotifications()
    {
        RedirectToIdentityProvider = (context) =>
        {
            string login_hint = context.OwinContext.Authentication.AuthenticationResponseChallenge.Properties.Dictionary["login_hint"];
            context.ProtocolMessage.LoginHint = login_hint;
            return Task.FromResult(0);
         }
    }