public ActionResult Index()
        {
            if (Request.QueryString["samlSessionId"] != null)
            {
                //re-login for saml authentication
                return(SignOut());
            }

            var tokenCookie = Request.Cookies[Constants.COOKIE_NAME];

            if (tokenCookie == null)
            {
                return(SignOut());
            }

            try
            {
                var api         = new MultiFactorSelfServiceApiClient(tokenCookie.Value);
                var userProfile = api.LoadProfile();

                return(View(userProfile));
            }
            catch (UnauthorizedException)
            {
                return(SignOut());
            }
        }
        public ActionResult Add(GoogleAuthenticatorModel model)
        {
            if (ModelState.IsValid)
            {
                var tokenCookie = Request.Cookies[Constants.COOKIE_NAME];
                if (tokenCookie == null)
                {
                    return(SignOut());
                }

                var api = new MultiFactorSelfServiceApiClient(tokenCookie.Value);

                try
                {
                    var result = api.AddTotpAuthenticator(model.Key, model.Otp);
                    if (result.Success)
                    {
                        return(RedirectToAction("Index", "Home"));
                    }
                    ModelState.AddModelError("Otp", Resources.Totp.WrongOtp);
                }
                catch (UnauthorizedException)
                {
                    return(SignOut());
                }
            }

            return(View("Index", model));
        }
        public ActionResult RemoveAuthenticator(string authenticator, string id)
        {
            var tokenCookie = Request.Cookies[Constants.COOKIE_NAME];

            if (tokenCookie == null)
            {
                return(SignOut());
            }

            var api = new MultiFactorSelfServiceApiClient(tokenCookie.Value);

            try
            {
                var userProfile = api.LoadProfile();
                if (userProfile.Count > 1) //do not remove last
                {
                    api.RemoveAuthenticator(authenticator, id);
                }

                return(RedirectToAction("Index"));
            }
            catch (UnauthorizedException)
            {
                return(SignOut());
            }
        }
        public ActionResult Index()
        {
            var tokenCookie = Request.Cookies[Constants.COOKIE_NAME];

            if (tokenCookie == null)
            {
                return(SignOut());
            }

            var api = new MultiFactorSelfServiceApiClient(tokenCookie.Value);

            try
            {
                var totpKey = api.CreateTotpKey();

                return(View(new GoogleAuthenticatorModel
                {
                    Link = totpKey.Link,
                    Key = totpKey.Key
                }));
            }
            catch (UnauthorizedException)
            {
                return(SignOut());
            }
        }