|
110 | 110 | import com.amazonaws.services.cognitoidentityprovider.AmazonCognitoIdentityProvider; |
111 | 111 | import com.amazonaws.services.cognitoidentityprovider.AmazonCognitoIdentityProviderClient; |
112 | 112 | import com.amazonaws.services.cognitoidentityprovider.model.GlobalSignOutRequest; |
| 113 | +import com.amazonaws.services.cognitoidentityprovider.model.InvalidUserPoolConfigurationException; |
113 | 114 | import com.amazonaws.util.StringUtils; |
114 | 115 |
|
115 | 116 | import org.json.JSONArray; |
@@ -1682,6 +1683,60 @@ public void onError(Exception e) { |
1682 | 1683 | }; |
1683 | 1684 | } |
1684 | 1685 |
|
| 1686 | + /** |
| 1687 | + * Delete the account of the currently logged-in user. |
| 1688 | + * @throws Exception if the user cannot be deleted successfully |
| 1689 | + */ |
| 1690 | + @WorkerThread |
| 1691 | + public void deleteUser() throws Exception { |
| 1692 | + final InternalCallback<Void> internalCallback = new InternalCallback<>(); |
| 1693 | + internalCallback.await(_deleteUser(internalCallback)); |
| 1694 | + } |
| 1695 | + |
| 1696 | + /** |
| 1697 | + * Delete the account of the currently logged-in user. |
| 1698 | + * @param callback the callback will be invoked to notify the success or |
| 1699 | + * failure of the deleteUser operation |
| 1700 | + */ |
| 1701 | + @AnyThread |
| 1702 | + public void deleteUser(final Callback<Void> callback) { |
| 1703 | + final InternalCallback<Void> internalCallback = new InternalCallback<>(callback); |
| 1704 | + internalCallback.async(_deleteUser(internalCallback)); |
| 1705 | + } |
| 1706 | + |
| 1707 | + private Runnable _deleteUser(final Callback<Void> callback) { |
| 1708 | + return () -> { |
| 1709 | + if (userpool == null) { |
| 1710 | + callback.onError(new InvalidUserPoolConfigurationException( |
| 1711 | + "A user pool must be configured in order to delete a user." |
| 1712 | + )); |
| 1713 | + } else { |
| 1714 | + CognitoUser currentUser = userpool.getCurrentUser(); |
| 1715 | + currentUser.deleteUserInBackground(new GenericHandler() { |
| 1716 | + @Override |
| 1717 | + public void onSuccess() { |
| 1718 | + signOut(SignOutOptions.builder().signOutGlobally(true).invalidateTokens(true).build(), new Callback<Void>() { |
| 1719 | + @Override |
| 1720 | + public void onResult(Void result) { |
| 1721 | + callback.onResult(result); |
| 1722 | + } |
| 1723 | + |
| 1724 | + @Override |
| 1725 | + public void onError(Exception e) { |
| 1726 | + callback.onError(e); |
| 1727 | + } |
| 1728 | + }); |
| 1729 | + } |
| 1730 | + |
| 1731 | + @Override |
| 1732 | + public void onFailure(Exception exception) { |
| 1733 | + callback.onError(exception); |
| 1734 | + } |
| 1735 | + }); |
| 1736 | + } |
| 1737 | + }; |
| 1738 | + } |
| 1739 | + |
1685 | 1740 | /** |
1686 | 1741 | * Federate tokens from custom identity providers into Cognito Identity Pool by providing the |
1687 | 1742 | * logins key and token |
|
0 commit comments