title: ASP.NET Identity OWIN Middleware Google OAuth2 AuthenticationManager SignIn not working
body: <p>I have created a simple ASP.NET MVC4 web site to test the new OWIN Authentication middleware, I decided to start with Google OAuth2, I have had struggle quite a bit with the configuration but I have managed to have Google to authorize the user, the problem I have right now is that OWIN is not authenticating the user.</p>
  
  <p>I think I have the proper settings in the web config</p>
  
  <pre><code>&lt;system.web&gt;
       &lt;authentication mode="None" /&gt;
  &lt;/system.web&gt;
  &lt;system.webServer&gt;
       &lt;modules&gt;
          &lt;remove name="FormsAuthenticationModule" /&gt;
       &lt;/modules&gt;
  &lt;/system.webServer&gt;
  </code></pre>
  
  <p>Then I have in the Startup class a very simple configuration</p>
  
  <pre><code>public partial class Startup
  {
      public void Configuration(IAppBuilder app)
      {
          ConfigureAuth(app);
      }
  
      public void ConfigureAuth(IAppBuilder app)
      {
          app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
          // Enable the External Sign In Cookie.
          app.SetDefaultSignInAsAuthenticationType(DefaultAuthenticationTypes.ExternalCookie);
          // Enable Google authentication.
          app.UseGoogleAuthentication(GetGoogleOptions());
      }
  
      private static GoogleOAuth2AuthenticationOptions GetGoogleOptions()
      {
          var reader = new KeyReader();
          var keys = reader.GetKey("google");
          var options = new GoogleOAuth2AuthenticationOptions()
          {
              ClientId = keys.Public,
              ClientSecret = keys.Private
          };
          return options;
      }
  }
  </code></pre>
  
  <p>In the <code>AccountController</code> I have coded the actions the following way which is again very simple but it should work.</p>
  
  <pre><code>[AllowAnonymous, HttpPost, ValidateAntiForgeryToken]
      public ActionResult ExternalLogin(string provider, string returnUrl)
      {
          return new ChallengeResult(provider, Url.Action("ExternalLoginCallback", "Account", new { ReturnUrl = returnUrl }));
      }
  
      [AllowAnonymous, HttpGet]
      public async Task&lt;ActionResult&gt; ExternalLoginCallback(string returnUrl)
      {
          var loginInfo = await AuthenticationManager.GetExternalLoginInfoAsync();
          if (loginInfo == null || !loginInfo.ExternalIdentity.IsAuthenticated)
          {
              return RedirectToAction("Login");
          }
  
          var identity = new ClaimsIdentity(new[] {
              new Claim(ClaimTypes.Name, loginInfo.DefaultUserName),
              new Claim(ClaimTypes.Email, loginInfo.Email)
          }, DefaultAuthenticationTypes.ExternalCookie);
  
          AuthenticationManager.SignOut(DefaultAuthenticationTypes.ExternalCookie);
  
          AuthenticationManager.SignIn(new AuthenticationProperties
                  {
                      IsPersistent = false
                  }, identity);
  
          return RedirectToLocal(returnUrl);
      }
  </code></pre>
  
  <p>The main problem I'm having is that the call to the method <code>AuthenticationManager.SignIn</code> doesn't appear to be doing anything, even though Google is granting access to the request, when the user is redirected to the home page in which I have the following code</p>
  
  <pre><code>@using Microsoft.AspNet.Identity
  @{
      Layout = "~/Views/Shared/_Main.cshtml";
  }
  &lt;h2&gt;Welcome&lt;/h2&gt;
  @{
      if (Request.IsAuthenticated)
      {
          &lt;p&gt;Welcome @User.Identity.GetUserName()&lt;/p&gt;
      }
      else
      {
          @Html.ActionLink("Login", "Login", "Account") 
      }
  }
  </code></pre>
  
  <p>The value of <code>Request.IsAuthenticated</code> is always false, anybody has an idea as to what am I missing here? From what I read online this should be working.</p>
  
  <p>I have cookies enabled in my browser and other Google OAuth samples that I have that rely on the <code>UserManager</code> class work but this simple implementation I have is not working</p>