We have our own OpenID Connect Provider. We want to pass custom query parameter in Authentication request using Owin middleware. And we cannot find the way how to implement
You're almost there! What's left is overriding built-in GoogleOAuth2AuthenticationProvider and here is the example how to do it:
class CustomGoogleAuthProvider : GoogleOAuth2AuthenticationProvider
{
public CustomGoogleAuthProvider()
{
OnApplyRedirect = (GoogleOAuth2ApplyRedirectContext context) =>
{
IDictionary props = context.OwinContext.Authentication.AuthenticationResponseChallenge.Properties.Dictionary;
string newRedirectUri = context.RedirectUri;
string[] paramertsToPassThrough = new[] { "login_hint", "hd", "anything" };
foreach (var param in paramertsToPassThrough)
{
if (props.ContainsKey(param))
{
newRedirectUri += string.Format("&{0}={1}", param, HttpUtility.UrlEncode(props[param]));
}
}
context.Response.Redirect(newRedirectUri);
};
}
}
OWIN middleware registration:
app.UseGoogleAuthentication(new Microsoft.Owin.Security.Google.GoogleOAuth2AuthenticationOptions()
{
// other config ...
Provider = new CustomGoogleAuthProvider(),
});
The result (by the way with current version (3.0.1) of Google OAuth middleware login_hint flows from Authentication parameters out-of-the-box):
