Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does my site redirect back to the Login screen when I click an external provider button?

I'm upgrading an ASP.Net MVC4 site to MVC5, and implementing the new OWIN Authentication methods in the process.

I've copied over the action methods from the Account controller on a blank MVC5 project.

The problem is, when I click an external provider button (e.g. Google) I just get redirected back to the login page again. The second time I click it, I do get taken to the Google account page, but then the browser gets redirected to the Account/External login page.

What's going on?

like image 614
Samuel Jack Avatar asked Mar 10 '14 11:03

Samuel Jack


2 Answers

Check the <authentication> element in your web.config file. It is probably still saying

<authentication mode="Forms">

Changing it to <authentication mode="None"> should fix the problem.

For good measure, remove the FormsAuthentication module from your webserver modules section:

<system.webServer>
  <modules>
     <remove name="FormsAuthentication" />
   </modules>
</system.webServer>

The problem is that the FormsAuthentication module looks out for any responses with a 401 (Unauthorised) code and changes them into a redirect request to your login page.

like image 161
Samuel Jack Avatar answered Oct 08 '22 20:10

Samuel Jack


I had the same issue and Samuel Jack's answer did help me, but I had to make a slight change.

For me, adding the

<remove name="FormsAuthentication" /> 

under the "handlers" section did not work. Instead, I had to add it under the "modules" section as below and the issue was resolved.

Here is how my web.config looks.

  <system.webServer>
    <modules>
      <remove name="FormsAuthentication" />
      <remove name="FormsAuthenticationModule" />
      <remove name="RoleManager" />
    </modules>

Note that in my case, there already was a

<remove name="FormsAuthenticationModule" />

in my web.config but that did not help solve the issue. I don't know how it got there so I left it alone.

Hope this helps.

like image 36
TwoPea Avatar answered Oct 08 '22 21:10

TwoPea