Esempio n. 1
0
        public async Task RemoveExternalLogin([FromBody] RemoveExternalLoginModel externalProvider, CancellationToken cancellationToken)
        {
            try
            {
                var user = await _operations.RepositoryManager.GetUserFromLoginAsync(externalProvider.Email, cancellationToken);

                if (user == null)
                {
                    throw new AdminControllerException($"The user with the email {externalProvider.Email} could not be found.", null);
                }

                await _operations.RepositoryManager.RemoveLoginAsync(user, externalProvider.Provider, externalProvider.ProviderKey, cancellationToken);
            }
            catch (Exception ex)
            {
                throw new AdminControllerException($"Error removing external login: {ex.Message}", ex);
            }
        }
Esempio n. 2
0
        public async Task <object> RemoveExternalLogin([FromBody] RemoveExternalLoginModel model)
        {
            var user = await GetCurrentUserAsync();

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

            if (result.Succeeded)
            {
                await _signInManager.SignInAsync(user, isPersistent : false);

                return(new
                {
                    success = true,
                    externalLogins = await GetExternalLoginsState()
                });
            }
            return(new
            {
                success = false,
                error = result.Errors.Select(x => x.Description)
            });
        }