|
37 | 37 | import com.amplifyframework.auth.cognito.options.AWSCognitoAuthConfirmSignInOptions; |
38 | 38 | import com.amplifyframework.auth.cognito.options.AWSCognitoAuthConfirmSignUpOptions; |
39 | 39 | import com.amplifyframework.auth.cognito.options.AWSCognitoAuthResendSignUpCodeOptions; |
| 40 | +import com.amplifyframework.auth.cognito.options.AWSCognitoAuthResendUserAttributeConfirmationCodeOptions; |
40 | 41 | import com.amplifyframework.auth.cognito.options.AWSCognitoAuthResetPasswordOptions; |
41 | 42 | import com.amplifyframework.auth.cognito.options.AWSCognitoAuthSignInOptions; |
42 | 43 | import com.amplifyframework.auth.cognito.options.AWSCognitoAuthSignOutOptions; |
43 | 44 | import com.amplifyframework.auth.cognito.options.AWSCognitoAuthSignUpOptions; |
| 45 | +import com.amplifyframework.auth.cognito.options.AWSCognitoAuthUpdateUserAttributeOptions; |
| 46 | +import com.amplifyframework.auth.cognito.options.AWSCognitoAuthUpdateUserAttributesOptions; |
44 | 47 | import com.amplifyframework.auth.cognito.options.AWSCognitoAuthWebUISignInOptions; |
45 | 48 | import com.amplifyframework.auth.cognito.util.AuthProviderConverter; |
46 | 49 | import com.amplifyframework.auth.cognito.util.CognitoAuthExceptionConverter; |
|
49 | 52 | import com.amplifyframework.auth.options.AuthConfirmSignInOptions; |
50 | 53 | import com.amplifyframework.auth.options.AuthConfirmSignUpOptions; |
51 | 54 | import com.amplifyframework.auth.options.AuthResendSignUpCodeOptions; |
| 55 | +import com.amplifyframework.auth.options.AuthResendUserAttributeConfirmationCodeOptions; |
52 | 56 | import com.amplifyframework.auth.options.AuthResetPasswordOptions; |
53 | 57 | import com.amplifyframework.auth.options.AuthSignInOptions; |
54 | 58 | import com.amplifyframework.auth.options.AuthSignOutOptions; |
55 | 59 | import com.amplifyframework.auth.options.AuthSignUpOptions; |
| 60 | +import com.amplifyframework.auth.options.AuthUpdateUserAttributeOptions; |
| 61 | +import com.amplifyframework.auth.options.AuthUpdateUserAttributesOptions; |
56 | 62 | import com.amplifyframework.auth.options.AuthWebUISignInOptions; |
57 | 63 | import com.amplifyframework.auth.result.AuthResetPasswordResult; |
58 | 64 | import com.amplifyframework.auth.result.AuthSessionResult; |
@@ -828,12 +834,21 @@ public void onError(Exception error) { |
828 | 834 | @Override |
829 | 835 | public void updateUserAttribute( |
830 | 836 | @NonNull AuthUserAttribute attribute, |
| 837 | + @NonNull AuthUpdateUserAttributeOptions options, |
831 | 838 | @NonNull Consumer<AuthUpdateAttributeResult> onSuccess, |
832 | 839 | @NonNull Consumer<AuthException> onError |
833 | 840 | ) { |
834 | 841 |
|
| 842 | + final Map<String, String> clientMetadata = new HashMap<>(); |
| 843 | + if (options instanceof AWSCognitoAuthUpdateUserAttributeOptions) { |
| 844 | + AWSCognitoAuthUpdateUserAttributeOptions cognitoOptions = |
| 845 | + (AWSCognitoAuthUpdateUserAttributeOptions) options; |
| 846 | + clientMetadata.putAll(cognitoOptions.getMetadata()); |
| 847 | + } |
| 848 | + |
835 | 849 | awsMobileClient.updateUserAttributes( |
836 | 850 | Collections.singletonMap(attribute.getKey().getKeyString(), attribute.getValue()), |
| 851 | + clientMetadata, |
837 | 852 | new Callback<List<UserCodeDeliveryDetails>>() { |
838 | 853 | @Override |
839 | 854 | public void onResult(List<UserCodeDeliveryDetails> result) { |
@@ -868,19 +883,38 @@ public void onError(Exception error) { |
868 | 883 | ); |
869 | 884 | } |
870 | 885 |
|
| 886 | + @Override |
| 887 | + public void updateUserAttribute( |
| 888 | + @NonNull AuthUserAttribute attribute, |
| 889 | + @NonNull Consumer<AuthUpdateAttributeResult> onSuccess, |
| 890 | + @NonNull Consumer<AuthException> onError |
| 891 | + ) { |
| 892 | + updateUserAttribute(attribute, AuthUpdateUserAttributeOptions.defaults(), onSuccess, onError); |
| 893 | + } |
| 894 | + |
871 | 895 | @Override |
872 | 896 | public void updateUserAttributes( |
873 | 897 | @NonNull List<AuthUserAttribute> attributes, |
| 898 | + @NonNull AuthUpdateUserAttributesOptions options, |
874 | 899 | @NonNull Consumer<Map<AuthUserAttributeKey, AuthUpdateAttributeResult>> onSuccess, |
875 | 900 | @NonNull Consumer<AuthException> onError |
876 | 901 | ) { |
| 902 | + |
| 903 | + final Map<String, String> clientMetadata = new HashMap<>(); |
| 904 | + if (options instanceof AWSCognitoAuthUpdateUserAttributesOptions) { |
| 905 | + AWSCognitoAuthUpdateUserAttributesOptions cognitoOptions = |
| 906 | + (AWSCognitoAuthUpdateUserAttributesOptions) options; |
| 907 | + clientMetadata.putAll(cognitoOptions.getMetadata()); |
| 908 | + } |
| 909 | + |
877 | 910 | Map<String, String> attributesMap = new HashMap<>(); |
878 | 911 | for (AuthUserAttribute attribute : attributes) { |
879 | 912 | attributesMap.put(attribute.getKey().getKeyString(), attribute.getValue()); |
880 | 913 | } |
881 | 914 |
|
882 | 915 | awsMobileClient.updateUserAttributes( |
883 | 916 | attributesMap, |
| 917 | + clientMetadata, |
884 | 918 | new Callback<List<UserCodeDeliveryDetails>>() { |
885 | 919 | @Override |
886 | 920 | public void onResult(List<UserCodeDeliveryDetails> result) { |
@@ -928,28 +962,68 @@ public void onError(Exception error) { |
928 | 962 | }); |
929 | 963 | } |
930 | 964 |
|
| 965 | + @Override |
| 966 | + public void updateUserAttributes( |
| 967 | + @NonNull List<AuthUserAttribute> attributes, |
| 968 | + @NonNull Consumer<Map<AuthUserAttributeKey, AuthUpdateAttributeResult>> onSuccess, |
| 969 | + @NonNull Consumer<AuthException> onError |
| 970 | + ) { |
| 971 | + updateUserAttributes( |
| 972 | + attributes, |
| 973 | + AuthUpdateUserAttributesOptions.defaults(), |
| 974 | + onSuccess, |
| 975 | + onError |
| 976 | + ); |
| 977 | + } |
| 978 | + |
931 | 979 | @Override |
932 | 980 | public void resendUserAttributeConfirmationCode( |
933 | 981 | @NonNull AuthUserAttributeKey attributeKey, |
| 982 | + @NonNull AuthResendUserAttributeConfirmationCodeOptions options, |
934 | 983 | @NonNull Consumer<AuthCodeDeliveryDetails> onSuccess, |
935 | 984 | @NonNull Consumer<AuthException> onError |
936 | 985 | ) { |
| 986 | + |
| 987 | + final Map<String, String> clientMetadata = new HashMap<>(); |
| 988 | + if (options instanceof AWSCognitoAuthResendUserAttributeConfirmationCodeOptions) { |
| 989 | + AWSCognitoAuthResendUserAttributeConfirmationCodeOptions cognitoOptions = |
| 990 | + (AWSCognitoAuthResendUserAttributeConfirmationCodeOptions) options; |
| 991 | + clientMetadata.putAll(cognitoOptions.getMetadata()); |
| 992 | + } |
| 993 | + |
937 | 994 | String attributeName = attributeKey.getKeyString(); |
938 | | - awsMobileClient.verifyUserAttribute(attributeName, new Callback<UserCodeDeliveryDetails>() { |
939 | | - @Override |
940 | | - public void onResult(UserCodeDeliveryDetails result) { |
941 | | - onSuccess.accept(convertCodeDeliveryDetails(result)); |
942 | | - } |
| 995 | + awsMobileClient.verifyUserAttribute( |
| 996 | + attributeName, |
| 997 | + clientMetadata, |
| 998 | + new Callback<UserCodeDeliveryDetails>() { |
| 999 | + @Override |
| 1000 | + public void onResult(UserCodeDeliveryDetails result) { |
| 1001 | + onSuccess.accept(convertCodeDeliveryDetails(result)); |
| 1002 | + } |
943 | 1003 |
|
944 | | - @Override |
945 | | - public void onError(Exception error) { |
946 | | - onError.accept(new AuthException( |
947 | | - "Failed to resend user attribute confirmation code", |
948 | | - error, |
949 | | - "See attached exception for more details" |
950 | | - )); |
951 | | - } |
952 | | - }); |
| 1004 | + @Override |
| 1005 | + public void onError(Exception error) { |
| 1006 | + onError.accept(new AuthException( |
| 1007 | + "Failed to resend user attribute confirmation code", |
| 1008 | + error, |
| 1009 | + "See attached exception for more details" |
| 1010 | + )); |
| 1011 | + } |
| 1012 | + }); |
| 1013 | + } |
| 1014 | + |
| 1015 | + @Override |
| 1016 | + public void resendUserAttributeConfirmationCode( |
| 1017 | + @NonNull AuthUserAttributeKey attributeKey, |
| 1018 | + @NonNull Consumer<AuthCodeDeliveryDetails> onSuccess, |
| 1019 | + @NonNull Consumer<AuthException> onError |
| 1020 | + ) { |
| 1021 | + resendUserAttributeConfirmationCode( |
| 1022 | + attributeKey, |
| 1023 | + AuthResendUserAttributeConfirmationCodeOptions.defaults(), |
| 1024 | + onSuccess, |
| 1025 | + onError |
| 1026 | + ); |
953 | 1027 | } |
954 | 1028 |
|
955 | 1029 | @Override |
|
0 commit comments