Passing parameters on login with OWIN

Hi There,

I’m using Microsoft.Owin version 4.1.0 in my Webforms Asp.Net (.net 4.7.2) web application.

I found lots of examples for Asp.net MVC (most of them can be used in my application) but not so many for webforms. I’ve managed to authenticate my application with Auth0 but I bumped into an obstacle. I want to pass parameters on logon and get back it on successful authentication. I found some examples but at the moment none of those are working for me.

Here is what am I using:

var properties = new AuthenticationProperties() { RedirectUri = ConfigurationManager.AppSettings["redirectURI"] };

properties.Dictionary.Add("someparameter", "some_data_to_pass"));

Context.GetOwinContext().Authentication.Challenge(properties, "Auth0");

also, I’m trying to access this dictionary on RedirectToIdentityProvider and try to pass it to the middleware

if (notification.ProtocolMessage.RequestType == OpenIdConnectRequestType.Authentication)
                    {
                        notification.ProtocolMessage.SetParameter("audience", apiAudience);
                        notification.ProtocolMessage.SetParameter("test", "testparam"); // here I try to pass the previously set param from the properties.Dictionary but don't know how so I just pass the 'test' param
                   
                    }

After successful authentication, I’m looking for the parameters in here

var data = HttpContext.Current.GetOwinContext();

Not sure if I’m on the right track or I’m completely wrong.

I would greatly appreciate any help.

1 Like

Even we are looking for a similar implementation. Does anybody have any leads with respect to this?

1 Like

I know some time has passed since this was active. However, I have a working solution. I have the following code running in the “RedirectToIdentityProvider” notification handler.

if (notification.ProtocolMessage.RequestType == OpenIdConnectRequestType.Authentication)
{
    var ctx = notification.OwinContext;

    object challengeObject;
    if (ctx.Environment.TryGetValue("security.Challenge", out challengeObject))
    {
        if (challengeObject is Tuple<string[], IDictionary<string, string>> challengeTuple)
        {
            string loginHint;

            if (challengeTuple.Item2.TryGetValue("login_hint", out loginHint))
            {
                notification.ProtocolMessage.LoginHint = loginHint;
            }
        }
    }
}

Then in your challenge:

                var authProps = new AuthenticationProperties()
                {
                    RedirectUri = VirtualPathUtility.ToAbsolute("~/Default.aspx"),
                };

                authProps.Dictionary.Add("login_hint", _authProvider.LoginHint);

                HttpContext.GetOwinContext().Authentication.Challenge(authProps, "Auth0");