public ActionResult LogOnToken(FormCollection form)
        {
            // We use return url as context
            WSFederationMessage message = WSFederationMessage.CreateFromNameValueCollection(new Uri("http://www.notused.com"), form);
            string returnUrl = message != null ? message.Context : null;

            var claimsPrincipal = User as IClaimsPrincipal;
            if (claimsPrincipal != null)
            {
                var claimsIdentity = claimsPrincipal.Identities[0];
                var nameIdentifierClaim = claimsIdentity.Claims.FirstOrDefault(c => c.ClaimType == "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier");
                var emailAddressClaim = claimsIdentity.Claims.FirstOrDefault(c => c.ClaimType == "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress");
                var identityProviderClaim = claimsIdentity.Claims.FirstOrDefault(c => c.ClaimType == "http://schemas.microsoft.com/accesscontrolservice/2010/07/claims/identityprovider");
                var nameClaim = claimsIdentity.Claims.FirstOrDefault(c => c.ClaimType == "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name");

                var userClaims = new UserClaims
                {
                    Name = nameClaim != null ? nameClaim.Value : null,
                    Email = emailAddressClaim != null ? emailAddressClaim.Value : null,
                    Provider = identityProviderClaim != null ? identityProviderClaim.Value : null,
                    NameIdentifier = nameIdentifierClaim != null ? nameIdentifierClaim.Value : null
                };

                if (string.IsNullOrEmpty(userClaims.Name) || string.IsNullOrEmpty(userClaims.Email))
                {
                    var user = _userManager.GetUserByClaims(userClaims.Provider, userClaims.NameIdentifier);
                    if (user == null)
                    {
                        return View("Register", userClaims);
                    }
                    else
                    {
                        Session.Add("user", user);
                    }
                }
                else
                {
                    ValidateLogin(userClaims);
                }
                if (!string.IsNullOrEmpty(returnUrl))
                {
                    return Redirect(returnUrl);
                }
                else
                {
                    return RedirectToAction("Index", "TaskLists");
                }
            }
            else
            {
                throw new HttpException((int)System.Net.HttpStatusCode.Unauthorized, "Unauthorized request");
            }
        }
        private PromptCloudNotes.Model.User ValidateLogin(UserClaims userClaims)
        {
            var user = _userManager.GetUserByClaims(userClaims.Provider, userClaims.NameIdentifier);
            if (user == null)
            {
                user = new PromptCloudNotes.Model.User() { Provider = userClaims.Provider, NameIdentifier = userClaims.NameIdentifier, Name = userClaims.Name, Email = userClaims.Email };
                _userManager.CreateUser(user);
            }

            Session.Add("user", user);

            return user;
        }
        //
        // POST: /Account/Register
        public ActionResult Register(UserClaims userClaims)
        {
            if (ModelState.IsValid)
            {
                var claimsPrincipal = User as IClaimsPrincipal;
                var nameIdentifierClaim = claimsPrincipal.Identities[0].Claims.FirstOrDefault(c => c.ClaimType == "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier");
                userClaims.NameIdentifier = nameIdentifierClaim.Value;
                var identityProviderClaim = claimsPrincipal.Identities[0].Claims.FirstOrDefault(c => c.ClaimType == "http://schemas.microsoft.com/accesscontrolservice/2010/07/claims/identityprovider");
                userClaims.Provider = identityProviderClaim.Value;

                var user = ValidateLogin(userClaims);
                return RedirectToAction("Index", "TaskLists");
            }
            else
            {
                return View(userClaims);
            }
        }