Single Sign On with ASP.Net Identity

Kiran Shah 1 Reputation point

There is requirement in my application to implement SSO using ASP.Net Identity (not using Form Authentication). I have implemented ASP.Net Identity in my 2 MVC applications for authentication. Also implemented SSO (Single Sign On) in both application, but when I log in into main application with correct login credentials, its not sharing authentication to the second application hence when I open second application it always redirect to the first application. I have added same machine key in both application See below Startup class I have implemented in my application.

public void ConfigureAuth(IAppBuilder app)
// Configure the db context, user manager and signin manager to use a single instance per request

        // Enable the application to use a cookie to store information for the signed in user
        // and to use a cookie to temporarily store information about a user logging in with a third party login provider
        // Configure the sign in cookie
        app.UseCookieAuthentication(new CookieAuthenticationOptions
            AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
            LoginPath = new PathString("/Account/Login"),
            CookieName = "Share1.SSO",
            //CookieDomain = "",//
            SlidingExpiration = true,
            Provider = new CookieAuthenticationProvider
                // Enables the application to validate the security stamp when the user logs in.
                // This is a security feature which is used when you change a password or add an external login to your account.  
                OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
                    validateInterval: TimeSpan.FromMinutes(30),
                    regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))

        AntiForgeryConfig.UniqueClaimTypeIdentifier = ClaimTypes.NameIdentifier;


Also on successful login, I also creates claims as below.

                var user = await UserManager.FindByNameAsync(username);

                var claims = new List<Claim>();
                claims.Add(new Claim(ClaimTypes.NameIdentifier, user.Id));
                claims.Add(new Claim(ClaimTypes.Name, username));
                var id = new ClaimsIdentity(claims,

                var ctx = Request.GetOwinContext();
                var authenticationManager = ctx.Authentication;
                authenticationManager.SignIn(new AuthenticationProperties()
                    AllowRefresh = true,
                    IsPersistent = true,
                    ExpiresUtc = DateTime.UtcNow.AddMinutes(30),
                    IssuedUtc = DateTime.UtcNow
                }, id);

But the SSO is not working when I publish on Azure portal. Please guide me to fix this issue asap.

Kiran Shah

Microsoft Identity Manager
Microsoft Identity Manager
A family of Microsoft products that manage a user's digital identity using identity synchronization, certificate management, and user provisioning.
607 questions
A set of technologies in the .NET Framework for building web applications and XML web services.
3,247 questions
{count} votes