title: Single Sign On using ASP.NET Identity between 2 ASP.NET MVC projects
body: <p>I have 2 web applications that both share the same main level domain as mentioned below so I can share cookies. Web.conifg in both the projects have same machine key and validation key. Since, I want to use Identity and <strong>NOT</strong> forms authenticaiton, I do not have an  node in either of my web.config file. I am able to create the Auth cookie successully from SSO and can view the authorized pages in SSO but I am still redirected to SSO login when I try to access an authorized view in MVC project.</p>
  
  <ol>
  <li>sso.domain.com  - MVC Project</li>
  <li>mvc.domain.com  - MVC Project</li>
  </ol>
  
  <p><strong>I have a startup.cs file in my SSO and MVC project like below:</strong></p>
  
  <pre><code>    public partial class Startup
  {
      public void Configuration(IAppBuilder app)
      {
          ConfigureAuth(app);
      }
  
      // For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301864
      public void ConfigureAuth(IAppBuilder app)
      {
          app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
  
          // Enable the application to use a cookie to store information for the signed in user
          app.UseCookieAuthentication(new CookieAuthenticationOptions
          {
              AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
              ExpireTimeSpan = TimeSpan.FromMinutes(3),                
              LoginPath = new PathString("/Login"),
              CookieName = "MyCookieName",
              CookieDomain = ".domain.com"               
          });
  
          app.UseTwoFactorRememberBrowserCookie(DefaultAuthenticationTypes.TwoFactorRememberBrowserCookie);
  
          AntiForgeryConfig.UniqueClaimTypeIdentifier = ClaimTypes.NameIdentifier;
      }
  }
  </code></pre>
  
  <p>Below is the code I have so far in the SSO project under the AccountController.cs. I call the IdentitySignin function below on validating the user against the database which creates the cookie:</p>
  
  <pre><code>        private void IdentitySignin(string userId, string name, string providerKey = null, bool isPersistent = false)
      {
          var claims = new List&lt;Claim&gt;();
  
          // create *required* claims
          claims.Add(new Claim(ClaimTypes.NameIdentifier, userId));
          claims.Add(new Claim(ClaimTypes.Name, name));            
  
          var identity = new ClaimsIdentity(claims, DefaultAuthenticationTypes.ApplicationCookie);
  
  
          //get the expiry minutes from config or use the default value of 30 minutes
          double expiryMinutes;
          expiryMinutes = double.TryParse(ConfigurationManager.AppSettings["AuthCookieExpiryMinutes"], out expiryMinutes) ? expiryMinutes : 30;
  
          // add to user here!
          AuthenticationManager.SignIn(new AuthenticationProperties()
          {
              AllowRefresh = true,
              IsPersistent = isPersistent,
              ExpiresUtc = DateTime.UtcNow.AddMinutes(expiryMinutes),
              IssuedUtc = DateTime.UtcNow                  
          }, identity);
      }
  
      private void IdentitySignout()
      {
          AuthenticationManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie, DefaultAuthenticationTypes.ExternalCookie);
      }
  
      private IAuthenticationManager AuthenticationManager
      {
          get
          {
              return HttpContext.GetOwinContext().Authentication;
          }
      }
  
      private async Task&lt;string&gt; GetVerifiedUserIdAsync()
      {
          var result = await AuthenticationManager.AuthenticateAsync(
              DefaultAuthenticationTypes.ApplicationCookie);
  
          if (result != null &amp;&amp; result.Identity != null
              &amp;&amp; !String.IsNullOrEmpty(result.Identity.GetUserId()))
          {
              return result.Identity.GetUserId();
          }
          return null;
      }
  </code></pre>