public static async Task <bool> TryDeleteCredentialAccountAsync(string userId) { bool deleted = false; try { await KeyCredentialManager.DeleteAsync(userId); deleted = true; } catch (Exception ex) { switch (ex.HResult) { case NTE_NO_KEY: // Key is already deleted. Ignore this error. break; case NTE_PERM: // Access is denied. Ignore this error. We tried our best. break; default: throw; } } return(deleted); }
static private async Task <bool> TryDeleteCredentialAccountAsync(string userName) { try { AppSettings.Current.WindowsHelloPublicKeyHint = null; await KeyCredentialManager.DeleteAsync(userName); return(true); } catch (Exception ex) { switch (ex.HResult) { case NTE_NO_KEY: // Key is already deleted. Ignore this error. break; case NTE_PERM: // Access is denied. Ignore this error. We tried our best. break; default: System.Diagnostics.Debug.WriteLine(ex.Message); break; } } return(false); }
/// <summary> /// Requests the deletion of a Microsoft Key credential. /// </summary> /// <param name="credentialName">Name of the credential to be deleted.</param> internal static async void DeleteCredential(string credentialName) { try { await KeyCredentialManager.DeleteAsync(credentialName); } catch (Exception ev) { MessageService.ShowWarning("Credential not deleted: " + ev.Message); //Debug.Write("Expected exception: " + ev.Message); } }
/// <summary> /// Function to be called when user requests deleting their account. /// Checks the KeyCredentialManager to see if there is a Passport for the current user /// Then deletes the local key associated with the Passport. /// </summary> public static async void RemovePassportAccountAsync(Account account) { // Open the account with Passport KeyCredentialRetrievalResult keyOpenResult = await KeyCredentialManager.OpenAsync(account.Username); if (keyOpenResult.Status == KeyCredentialStatus.Success) { // In the real world you would send key information to server to unregister //e.g. RemovePassportAccountOnServer(account); } // Then delete the account from the machines list of Passport Accounts await KeyCredentialManager.DeleteAsync(account.Username); }
public static async void RemovePassportAccountAsync(UserAccount account) { //Open the account with Windows Hello KeyCredentialRetrievalResult keyOpenResult = await KeyCredentialManager.OpenAsync(account.Username); if (keyOpenResult.Status == KeyCredentialStatus.Success) { // In the real world you would send key information to server to unregister AuthService.AuthService.Instance.PassportRemoveUser(account.UserId); } //Then delete the account from the machines list of Passport Accounts await KeyCredentialManager.DeleteAsync(account.Username); }
public async Task <IActionResult> Keys(string id) { _logger.LogInformation("Deleting authentication key {0} from tenant {1} by {2}", id, User.Tenant(), User.Identity?.Name); var key = await _keyManager.FindByIdAsync(id); if (key == null) { return(NotFound()); } await _keyManager.DeleteAsync(key); return(Ok()); }
/// <summary> /// 删除并注销用户 /// </summary> /// <returns></returns> public static async Task DeleteUserAsync() { if (await CheckSupportAsync().ConfigureAwait(false)) { try { ApplicationData.Current.LocalSettings.Values["WindowsHelloPublicKeyForUser"] = null; await KeyCredentialManager.DeleteAsync(CredentialName); } catch (Exception) { } } }
/// <summary> /// Checks the KeyCredentialManager to see if there is a Passport for the current user and /// sends the informaton to the server to unregister it. /// /// Then deletes the local key associated with the Passport. /// </summary> private async void PassportDelete() { KeyCredentialRetrievalResult keyOpenResult = await KeyCredentialManager.OpenAsync(activeAccount.Email); if (keyOpenResult.Status == KeyCredentialStatus.Success) { var userKey = keyOpenResult.Credential; var publicKey = userKey.RetrievePublicKey(); // Send key information to server to unregister it DeletePassportServerSide(); } await KeyCredentialManager.DeleteAsync(activeAccount.Email); }
/// <summary> /// Checks the KeyCredentialManager to see if there is a Passport for the current user and /// sends the informaton to the server to unregister it. /// /// Then deletes the local key associated with the Passport. /// </summary> private async void PassportDelete() { KeyCredentialRetrievalResult keyOpenResult = await KeyCredentialManager.OpenAsync(activeAccount.Email); if (keyOpenResult.Status == KeyCredentialStatus.Success) { var userKey = keyOpenResult.Credential; var publicKey = userKey.RetrievePublicKey(); // Send key information to server to unregister it DeletePassportServerSide(); } await KeyCredentialManager.DeleteAsync(activeAccount.Email); rootPage.NotifyUser("User " + activeAccount.Email + " deleted.", NotifyType.StatusMessage); button_Forget.IsEnabled = false; button_Forget.Content = "User Forgotten."; }
/// <summary> /// Delete the passport account async. /// Returns zero, if the operation was successful, /// 3 if the key is already deleted, /// 2 if the access was denied and 1 if an unknown /// error occurred /// </summary> /// <param name="accountId">The id of the account to delete</param> /// <returns>A Task with an integer</returns> private static async Task <int> DeletePassportAccountAsync(string accountId) { try { // Try to delete the account await KeyCredentialManager.DeleteAsync(accountId); return(0); } catch (Exception e) { switch (e.HResult) { case NTE_NO_KEY: // Key is already deleted. Ignore this error. return(3); case NTE_PERM: // Access is denied. Ignore this error. We tried our best. return(2); default: // An unknown error occurred return(1); } } }