我正试图将OWIN身份验证与仅谷歌身份验证一起使用ie-我的应用程序的用户只有在他们有谷歌账户的情况下才存在
我已经这样配置了我的Auth配置:
public partial class Startup
{
public void ConfigureAuth(IAppBuilder app)
{
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ExternalCookie,
CookieName = CookieAuthenticationDefaults.CookiePrefix + "External",
ExpireTimeSpan = TimeSpan.FromMinutes(5),
LoginPath = new PathString("/authentication"),
});
app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions
{
ClientId = "xxx123",
ClientSecret = "xxx456",
});
}
}
我的AuthenticationController
有一个索引方法:
[AllowAnonymous]
public ActionResult Index()
{
Request.GetOwinContext().Authentication.Challenge(new AuthenticationProperties
{
RedirectUri = Url.Action("ExternalLoginCallback")
});
return new HttpUnauthorizedResult();
}
当我进入受限页面时,我会得到
HTTP错误404.15-找不到请求筛选模块配置为拒绝查询字符串过长的请求。
它多次命中我的AuthenticationControllers Index方法。。。
知道我没有正确配置什么吗?
编辑
我的ExternalLoginCallback
看起来像:
[AllowAnonymous]
public async Task<ActionResult> ExternalLoginCallback(string returnUrl)
{
}
注意-如果我在这个方法上放一个断点,这个方法永远不会被命中
我的问题是没有将提供程序类型传递给Challenge
方法-
将我的索引操作方法更改为:
[AllowAnonymous]
public ActionResult Index()
{
var properties = new AuthenticationProperties
{
RedirectUri = Url.Action("ExternalLoginCallback")
};
//challenge
Request.RequestContext.HttpContext.GetOwinContext().Authentication.Challenge(properties, "Google");
//if above didn't handle it, return unauth.
return new HttpUnauthorizedResult();
}