【问题标题】:How to update attributes using Cognito if user is not confirmed?如果未确认用户,如何使用 Cognito 更新属性?
【发布时间】:2017-01-22 14:29:04
【问题描述】:

如果用户没有使用 AuthenticationHandler 登录,也没有确认该用户,是否可以更新用户属性?这个想法是,当用户注册他们的帐户时,并且在“确认”他们的帐户之前,该用户将他们的电子邮件更改为不同的电子邮件地址。我尝试使用 UpdateAttributesHandler,但收到异常。

(1) 如果对于用户对象,我使用 userpool.getCurrentUser() 或 userpool.getUser(),我会收到以下异常:

W/System.err: com.amazonaws.mobileconnectors.cognitoidentityprovider.exceptions.CognitoNotAuthorizedException: User-ID is null

(2) 如果对于用户对象,我使用 userpool.getUser(""),我会收到以下异常:

W/System.err: com.amazonaws.mobileconnectors.cognitoidentityprovider.exceptions.CognitoNotAuthorizedException: user is not authenticated

(3) 如果对于用户对象,我使用 userpool.getUser(""),我收到以下异常:

W/System.err: com.amazonaws.mobileconnectors.cognitoidentityprovider.exceptions.CognitoNotAuthorizedException: user is not authenticated

我的实现如下:

       user = userPool.getCurrentUser();
       UpdateAttributesHandler handler = new UpdateAttributesHandler() {
            @Override
            public void onSuccess(List<CognitoUserCodeDeliveryDetails> list) {
                     // set listener
                mOnCognitoUpdateUserAttributesListener.onSuccess(list);
            }

            @Override
            public void onFailure(Exception exception) {
                exception.printStackTrace();
                // resend code failed
                Log.e(TAG, exception.toString());
                // set listener
                mOnCognitoUpdateUserAttributesListener.onFailure(exception);
            }
        };
        user.updateAttributesInBackground(userAttributes, handler);

这个请求每次都失败,除了我之前表达的例外。能够更新用户的信息缺少什么?这在 AWS 文档中没有提到:https://docs.aws.amazon.com/cognito/latest/developerguide/using-amazon-cognito-user-identity-pools-android-sdk.html

谢谢你!

【问题讨论】:

  • 也许你的用户已经登出,但是 userPool.getCurrentUser();正在为您提供缓存的用户...所以请尝试再次登录
  • ...你能在哪里解决这个问题?我有类似的错误。
  • 我无法解决这个问题,但是,我能够收到答案。我向 AWS 技术支持开了一张票,他们说必须先验证用户才能执行更改密码、忘记密码、登录和更改用户属性等功能。

标签: android amazon-web-services amazon-cognito


【解决方案1】:

这样做的一种方法是根据您的架构中的要求指定电子邮件。使用 AdminCreateUser 配置用户服务器端,并通过 SMS 将密码发送给用户。用户首次登录时,必须设置邮箱。

【讨论】:

    猜你喜欢
    • 2020-12-03
    • 2022-01-21
    • 1970-01-01
    • 2019-12-29
    • 2021-02-19
    • 2018-01-05
    • 1970-01-01
    • 2020-02-16
    • 2022-10-02
    相关资源
    最近更新 更多