【发布时间】:2014-09-17 09:24:43
【问题描述】:
我们有自己的 OpenID Connect Provider。我们想使用 Owin 中间件在身份验证请求中传递自定义查询参数。而且我们找不到如何使用 Microsoft.Owin.Security.OpenIdConnect 程序集来实现这一点。甚至我们也找不到如何在 Authentication Request 中添加标准请求参数(例如“login_hint 参数”)。
例如,Google 有“login_hint”和“hd”参数(https://developers.google.com/accounts/docs/OAuth2Login#sendauthrequest),我们希望有几乎相同的参数。但我们甚至找不到如何使用 Owin 将这些参数发送给 Google。试过这段代码:
var googleOptions = new GoogleOAuth2AuthenticationOptions()
{
ClientId = "...",
ClientSecret = "...",
};
app.UseGoogleAuthentication(googleOptions);
...
public ActionResult ExternalLogin(string provider)
{
var ctx = Request.GetOwinContext();
var properties = new AuthenticationProperties();
properties.Dictionary.Add("login_hint ", "myemail@gmail.com");
properties.Dictionary.Add("hd", "hd");
ctx.Authentication.Challenge(properties, provider);
return new HttpUnauthorizedResult();
}
但是会生成没有“login_hint”和“hd”参数的认证请求url。
非常感谢您提供解决此问题的任何帮助。
【问题讨论】:
-
您的密钥末尾有空格是否有原因,因为 login_hint 末尾有空格?如果没有空格,我似乎无法将其添加到
ctx.Authentication.Challenge,但该空格永远不会被解析出来,它会创建一个带有空格的重定向,我认为这不起作用。
标签: c# asp.net-mvc owin katana openid-connect