首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >AWS认知新密码续传- Android

AWS认知新密码续传- Android
EN

Stack Overflow用户
提问于 2016-11-24 16:25:26
回答 1查看 867关注 0票数 2

希望有人能在这方面帮助我,我已经尝试了几天了。我正在构建一个Android应用程序,并集成Amazon Cognito登录。我想创建用户作为管理员只在亚马逊Cognito使用管理面板。执行此操作时,一个要求是用户必须更改其密码。在匿名类CognitoUserPoolSignInProvider中,为了使用新密码对用户进行身份验证,我在匿名类中使用了以下代码:

代码语言:javascript
复制
@Override
    public void authenticationChallenge(final ChallengeContinuation continuation) {

        if ("NEW_PASSWORD_REQUIRED".equals(continuation.getChallengeName())) {
            NewPasswordContinuation newPasswordContinuation = (NewPasswordContinuation) continuation;
            newPasswordContinuation.setPassword("users new password goes here");
            continuation.continueTask();
        }

    }

我有一个单独的Activity类,叫做ChangePassword。这将链接到用户界面,并从用户获取编辑文本框中的输入。

代码语言:javascript
复制
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_change_password);


        password = (EditText) findViewById(R.id.newPassword);
        submit = (Button) findViewById(R.id.submit);

        String pass = password.getText().toString();

如何让用户输入到匿名类中以设置新密码?任何帮助都是非常感谢的。

EN

回答 1

Stack Overflow用户

发布于 2016-12-20 09:58:22

您需要使用单击回调按钮来拉入用户密码。现在编写代码时,密码将被设置为空字符串(或创建时EditText字段中的任何内容)。

从这个开始:

代码语言:javascript
复制
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_change_password);
    final EditText password = (EditText) findViewById(R.id.newPassword);
    Button submit = (Button) findViewById(R.id.submit);
    submit.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            String pass = password.getText().toString();
        }
    });
}

单击操作setup按钮后,创建一个覆盖authenticationChallenge方法的类实例。将该类传递给适当的AWS类进行身份验证。如下所示:

代码语言:javascript
复制
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_change_password);
    final EditText password = (EditText) findViewById(R.id.newPassword);
    Button submit = (Button) findViewById(R.id.submit);
    submit.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            String pass = password.getText().toString();
            AuthenticationHandler h = new AuthenticationHandler() {
                @Override
                public void onSuccess(CognitoUserSession cognitoUserSession, CognitoDevice cognitoDevice) { }
                @Override
                public void getAuthenticationDetails(AuthenticationContinuation authenticationContinuation, String s) { }
                @Override
                public void getMFACode(MultiFactorAuthenticationContinuation multiFactorAuthenticationContinuation) { }
                @Override
                public void authenticationChallenge(ChallengeContinuation continuation) {
                    if ("NEW_PASSWORD_REQUIRED".equals(continuation.getChallengeName())) {
                        NewPasswordContinuation newPasswordContinuation = (NewPasswordContinuation) continuation;
                        newPasswordContinuation.setPassword(pass);
                        continuation.continueTask();
                    }
                }
                @Override
                public void onFailure(Exception e) { }
            };
            CognitoUserPool pool = new CognitoUserPool(getApplicationContext(), "poolId", "clientId", "clientSecret", Regions.US_WEST_2);
            pool.getUser("userId").getSession(h);
        }
    });
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40781235

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档