外部认证不重定向到外部网站
-
21-12-2019 - |
题
有一个奇怪的事情发生在这里。
我已经建立了一个ASP.NET MVC5的网站,并有当地账户工作现通过ASP.NET 身份。
我现在试图使得外部认证,但有一些怪事发生。
我敢肯定,我随后的正确步骤。我有这个在我的启动。Auth.cs:
public void ConfigureAuth(IAppBuilder app)
{
// Enable the application to use a cookie to store information for the signed in user
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Account/Login")
});
// Use a cookie to temporarily store information about a user logging in with a third party login provider
app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
// Uncomment the following lines to enable logging in with third party login providers
//app.UseMicrosoftAccountAuthentication(
// clientId: "",
// clientSecret: "");
//app.UseTwitterAuthentication(
// consumerKey: "",
// consumerSecret: "");
//app.UseFacebookAuthentication(
// appId: "",
// appSecret: "");
app.UseGoogleAuthentication();
}
当用户点击的链接登录与谷歌,ExternalLogin方法被称为:
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public ActionResult ExternalLogin(string provider, string returnUrl)
{
// Request a redirect to the external login provider
return new ChallengeResult(provider, Url.Action("ExternalLoginCallback", "Account", new { ReturnUrl = returnUrl }));
}
我已经验证通过调试进入ExecuteResult方法的ChallengeResult类:
public override void ExecuteResult(ControllerContext context)
{
var properties = new AuthenticationProperties() { RedirectUri = RedirectUri };
if (UserId != null)
{
properties.Dictionary[XsrfKey] = UserId;
}
context.HttpContext.GetOwinContext().Authentication.Challenge(properties, LoginProvider);
}
然而,在浏览器,什么也不会发生。我只是得到了一个空白页面,我希望重定向到谷歌登录网页。
没有任何错误报告的。
另一件有趣的事情是,我试图创建的另一个MVC5应用程序,但我得到一个"目的参考,不设置为对象的一个实例"弹在VS2013,并将所得到的项目缺少的账户的控制,通常有默认。
我修复的装VS2013,我已重新安装更1和我还更新了所有Nuget包的解决方案。
我已经跑出来的想法的下一步去哪里。
1更新 思想,这可能是关于我的电脑,我已经部署的网站,以湛蓝,而该问题仍然存在。这是不是意味着它可能是关于一个失踪的组件,而这是不正确报告?我已经运行fusionlog,但是我看没有约束力的失败。
纺丝立一个新的虚拟机与干净安装Windows8和VS2013看到,如果我可以获得一个新的项目在那里工作。
更新2 好的,只是跑了另一轮的"网络"捕,而当户选择外部提供商,它不会后来的ExternalLogin行动,但是响应是一个401未经授权的。有什么可以引起这?
解决方案
Ok,
我想出什么(要部)的问题。
首先,我还是不知道为什么当我创建一个视的项目,我没有得到一个支架'ed AccountController类。
然而,看来我的问题是,我登录的按钮是通过"谷歌"而不是"谷歌"的供应商。
说真的!?我有点惊讶的是,壳体会问题提供者的名称,但那里你去。
其他提示
这不是回答你的问题,但它回应一个非常类似的问题
如果你不得不同时欧文2.0和迁移到2.1
该_ExternalLoginsListPartial需要改变这样的:
<button type="submit" class="btn btn-default" id="@p.AuthenticationType" name="Partner" value="@p.AuthenticationType" title="Log in using your @p.Caption account">@p.AuthenticationType</button>
到这个
<button type="submit" class="btn btn-default" id="@p.AuthenticationType" name="provider" value="@p.AuthenticationType" title="Log in using your @p.Caption account">@p.AuthenticationType</button>
唯一的变化是按钮的名称但是,这可能会打破你的头像我和我2天的工作,以找到该问题。
也许这就是解释新的同时欧文版本,如果不是必须的东西在指定国家的首都。
我只是碰到了同样的问题,与我的ASP.Net (#)服务器。我是传递正确的AuthenticationType成的挑战的方法,但仍然得到一个空白页。
原来的问题是以我加入保护身份验证供应商进入的同时欧文的管道,在启动时。大约是我的工作顺序:
app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
OAuthBearerOptions = new OAuthBearerAuthenticationOptions();
var authServerOptions = new OAuthAuthorizationServerOptions
{
...
};
// Token Generation
app.UseOAuthAuthorizationServer(authServerOptions);
app.UseOAuthBearerAuthentication(OAuthBearerOptions);
// Configure Google External Login
GoogleAuthOptions = new GoogleOAuth2AuthenticationOptions()
{
ClientId = xxxx,
ClientSecret = xxxx,
Provider = new GoogleAuthProvider()
};
app.UseGoogleAuthentication(GoogleAuthOptions);
app.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll);
app.UseWebApi(config);
以前我加入UseCors+UseWebApi方法之前UseGoogleAuthentication方法。
我发现这个职位是有用的:http://coding.abel.nu/2014/06/understanding-the-owin-external-authentication-pipeline/