public async Task <ActionResult> ExternalLoginCallback(string returnUrl)
        {
            var loginInfo = await AuthenticationManager.GetExternalLoginInfoAsync();

            if (loginInfo == null)
            {
                return(RedirectToAction("Login"));
            }

            // Sign in the user with this external login provider if the user already has a login
            LoginExternalResponse response = await this.Membership.LoginExternalAsync(new LoginExternalRequest()
            {
                LoginProvider = loginInfo.Login.LoginProvider,
                ProviderKey   = loginInfo.Login.ProviderKey,
            });

            if (response.Success)
            {
                ClaimsIdentity identity = response.ClaimIdentity.ConvertToClaimsIdentity();
                SignInAsync(identity, IsPersistent: false);
                return(RedirectToLocal(returnUrl));
            }
            else
            {
                // If the user does not have an account, then prompt the user to create an account
                ViewBag.ReturnUrl     = returnUrl;
                ViewBag.LoginProvider = loginInfo.Login.LoginProvider;
                return(View("ExternalLoginConfirmation", new ExternalLoginConfirmationViewModel {
                    UserName = loginInfo.DefaultUserName
                }));
            }
        }
        /// <summary>
        /// Login User by external provider and return ClaimsIdentity
        /// </summary>
        /// <param name="request">Instance of LoginExternalRequest</param>
        /// <returns>Instance of LoginExternalResponse</returns>
        public async Task <LoginExternalResponse> LoginExternalAsync(LoginExternalRequest request)
        {
            LoginExternalResponse response = new LoginExternalResponse();

            try
            {
                string authType = EnumStringValue.GetStringValue(request.AuthenticationType);

                AspNetUser user = await UserManager.FindAsync(new UserLoginInfo(request.LoginProvider, request.ProviderKey));

                ClaimsIdentity identity = await UserManager.CreateIdentityAsync(user, authType);

                response.ClaimIdentity = identity.ConvertToClaimIdentityView();
                response.Success       = true;
            }
            catch (Exception e)
            {
                response.Success = false;
                response.Errors.Add(e.Message);
            }

            return(response);
        }
        /// <summary>
        /// Login User by external provider and return ClaimsIdentity
        /// </summary>
        /// <param name="request">Instance of LoginExternalRequest</param>
        /// <returns>Instance of LoginExternalResponse</returns>
        public async Task<LoginExternalResponse> LoginExternalAsync(LoginExternalRequest request)
        {
            LoginExternalResponse response = new LoginExternalResponse();

            try
            {
                string authType = EnumStringValue.GetStringValue(request.AuthenticationType);

                AspNetUser user = await UserManager.FindAsync(new UserLoginInfo(request.LoginProvider, request.ProviderKey));
                ClaimsIdentity identity = await UserManager.CreateIdentityAsync(user, authType);

                response.ClaimIdentity = identity.ConvertToClaimIdentityView();
                response.Success = true;
            }
            catch (Exception e)
            {
                response.Success = false;
                response.Errors.Add(e.Message);
            }

            return response;
        }