在MVC5中使用OAuth时,无限循环返回到身份验证页面 [英] infinite loop going back to authentication page when using OAuth in MVC5

查看:159
本文介绍了在MVC5中使用OAuth时,无限循环返回到身份验证页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一个使用MVC5和OAuth来利用Google/Facebook身份验证的网页.

I have written a webpage that takes advantage of Google/Facebook auth using MVC5 and OAuth.

有时候,我可以使用Facebook或Google进行很好的身份验证.效果很好.

Sometimes, I'm able to auth very well using either Facebook or Google. It works quite well.

然而,经常发生的是:

  1. 导航到登录页面.
  2. 选择Google或Facebook.
  3. 提供帐户信息,以获取必要的重定向.
  4. 重定向回登录页面,但未登录.

我没有收到(或没有在正确的位置查看)任何提示我的错误-我在Azure上使用SSL进行托管.

I'm not receiving (or not looking in the right place) any errors that clue me in - I am using SSL on Azure for hosting.

有人有提示为什么有时起作用,有时却不起作用的提示吗?感觉好像是cookie的事,还是服务器端的配置问题?我不知道为什么它有时会起作用,有时会不起作用.

Does anyone have tips for why it sometimes works, and sometimes does not? This feels like it could be a cookie thing, or maybe a server side configuration problem? I can't figure out why it would sometimes work and sometimes wouldn't work.

我尝试过:

  • 使用另一台从未登录过的计算机( 出Cookie),同样的问题.
  • 清除我的cookie缓存,同样的问题.
  • Using a second machine, one that has never logged in before (to rule out cookies), same problem.
  • Clearing my cookie cache, same problem.

我的配置方式:

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: "abc",
       appSecret: "123");

    app.UseGoogleAuthentication();
}

我已经按照本教程在MVC5中使用OAuth:

I've followed this tutorial to use OAuth in MVC5: Create an ASP.NET MVC 5 App with Facebook, Twitter, LinkedIn and Google OAuth2 Sign-on (C#)

推荐答案

这是一个主要问题,您的应用程序将随机地开始进入无限循环,有时重新部署该应用程序使其可以工作,但只能是临时的.我发现解决此问题的快速方法是使用@cooper注释的nuget软件包kentor.owincookiesaver.您应该在owin启动类中的cookieauthentication调用之前调用此类,如下所示

this is a major issue where randomly your application will start going into an infinite loop and some times redeploying the application makes it work but only temporary. the quick way i found to address this issue is using nuget package kentor.owincookiesaver as commented by @cooper. you should make a call to this class before cookieauthentication call in the owin startup class as shown below

app.UseKentorOwinCookieSaver();

app.UseCookieAuthentication(new CookieAuthenticationOptions());

很明显,owin和katana中存在一个错误,您的cookie刚刚消失并且可以解决此问题.

Apparently there is a bug in owin and katana where your cookie just disappear and this fixes it.

这篇关于在MVC5中使用OAuth时,无限循环返回到身份验证页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆