/// <summary>
        /// Remove associated login by LoginProvider and ProviderKey
        /// </summary>
        /// <param name="request">Instance of RemoveLoginRequest</param>
        /// <returns>Instance of RemoveLoginResponse</returns>
        public async Task <RemoveLoginResponse> RemoveLoginAsync(RemoveLoginRequest request)
        {
            RemoveLoginResponse response = new RemoveLoginResponse();

            try
            {
                IdentityResult result = await UserManager.RemoveLoginAsync(request.UserId.ToString(), new UserLoginInfo(request.LoginProvider, request.ProviderKey));

                if (!result.Succeeded)
                {
                    response.AddErrors(response.Errors);
                    response.Success = false;
                }
                else
                {
                    response.Success = true;
                }
            }
            catch (Exception e)
            {
                response.Success = false;
                response.Errors.Add(e.Message);
            }

            return(response);
        }
        public async Task <IHttpActionResult> RemoveLogin(RemoveLoginRequest model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            IdentityResult result;

            if (model.LoginProvider == LocalLoginProvider)
            {
                result = await UserManager.RemovePasswordAsync(User.Identity.GetUserId());
            }
            else
            {
                result = await UserManager.RemoveLoginAsync(User.Identity.GetUserId(),
                                                            new UserLoginInfo(model.LoginProvider, model.ProviderKey));
            }

            if (!result.Succeeded)
            {
                return(GetErrorResult(result));
            }

            return(Ok());
        }
        public async Task RemoveLoginAsync([FromBody] RemoveLoginRequest request)
        {
            var cp   = _httpContextAccessor.HttpContext.User;
            var user = await _userManager.GetUserAsync(cp);

            var result = await _userManager.RemoveLoginAsync(user, request.LoginProvider, request.ProviderKey);

            if (result.Succeeded)
            {
                await _signInManager.RefreshSignInAsync(user);
            }
            else
            {
                throw new System.Exception(string.Join(",", result.Errors.Select(t => t.Description)));
            }
        }
예제 #4
0
        /// <summary>
        /// Remove associated login by LoginProvider and ProviderKey
        /// </summary>
        /// <param name="request">Instance of RemoveLoginRequest</param>
        /// <returns>Instance of RemoveLoginResponse</returns>
        public async Task<RemoveLoginResponse> RemoveLoginAsync(RemoveLoginRequest request)
        {
            RemoveLoginResponse response = new RemoveLoginResponse();

            try
            {
                IdentityResult result = await UserManager.RemoveLoginAsync(request.UserId.ToString(), new UserLoginInfo(request.LoginProvider, request.ProviderKey));

                if (!result.Succeeded)
                {
                    response.AddErrors(response.Errors);
                    response.Success = false;
                }
                else
                {
                    response.Success = true;
                }

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

            return response;
        }