2

我正在尝试创建一个简单的 android/aws 项目,但收到一个错误,我不知道去哪里找。请注意确定是否重要,但我正在尝试将我的应用程序连接到身份池以让用户使用电子邮件地址登录。

public class MainActivity extends AppCompatActivity {

    //AWS Housekeeping
    public static PinpointManager pinpointManager;
    private DynamoDBMapper dynamoDBMapper;
    private final String POOL_ID = "xxxxxxxx";
    private final String USER_POOL = "xxxxxxxxx";

    private AWSCredentialsProvider awsCredentialsProvider;
    private AWSConfiguration awsConfiguration;

    private Button loginBtm;
    private Button createUserBtm;
    private EditText emailField;
    private EditText passwordField;



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        createUserBtm = findViewById(R.id.createButton);
        loginBtm = findViewById(R.id.loginButton);
        emailField = findViewById(R.id.usernameField);
        passwordField = findViewById(R.id.passwordField);

        final Intent newUserIntent = new Intent(this, NewUserActivity.class);
        final Intent signInIntent = new Intent(this, HomeActivity.class);


        AWSMobileClient.getInstance().initialize(this, new AWSStartupHandler() {
            @Override
            public void onComplete(AWSStartupResult awsStartupResult) {

                // Obtain the reference to the AWSCredentialsProvider and AWSConfiguration objects
                awsCredentialsProvider = AWSMobileClient.getInstance().getCredentialsProvider();
                awsConfiguration = AWSMobileClient.getInstance().getConfiguration();


                // Use IdentityManager #getUserID to fetch the identity id.
                IdentityManager.getDefaultIdentityManager().getUserID(new IdentityHandler() {
                    @Override
                    public void onIdentityId(String identityId) {
                        Log.d("YourMainActivity", "Identity ID = " + identityId);

                        // Use IdentityManager#getCachedUserID to
                        //  fetch the locally cached identity id.
                        final String cachedIdentityId =
                                IdentityManager.getDefaultIdentityManager().getCachedUserID();
                    }

                    @Override
                    public void handleError(Exception exception) {
                        Log.d("YourMainActivity", "Error in retrieving the identity: " + exception);
                    }
                });
            }
        }).execute();





        createUserBtm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(newUserIntent);
            }
        });

        loginBtm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(emailField.getText().toString() != null && passwordField.getText().toString() != null){
                    CognitoUserPool userPool = new CognitoUserPool(getApplicationContext(), POOL_ID, USER_POOL, null, Regions.US_EAST_1);
                    CognitoUser cognitoUser = userPool.getUser();
                    cognitoUser.getSessionInBackground(authenticationHandler);
                    startActivity(signInIntent);
                }
            }
        });



    }

    class loginUser extends AsyncTask<Void, Void, Void>{

        DynamoDBMapper dynamoDBMapper;
        String username;
        String password;


        @Override
        protected void onPreExecute(){

            username = emailField.getText().toString();
            password = passwordField.getText().toString();

        }


        @Override
        protected Void doInBackground(Void... voids) {

            //Instantiate an AmazonBynamoDBMapperClient
            AmazonDynamoDBClient dynamoDBClient = new AmazonDynamoDBClient(AWSMobileClient.getInstance().getCredentialsProvider());
            this.dynamoDBMapper = DynamoDBMapper.builder()
                    .dynamoDBClient(dynamoDBClient)
                    .awsConfiguration(AWSMobileClient.getInstance().getConfiguration())
                    .build();

            return null;
        }
    }


    final AuthenticationHandler authenticationHandler = new AuthenticationHandler() {
        @Override
        public void onSuccess(CognitoUserSession userSession, CognitoDevice newDevice) {
            Log.i("Success: ", userSession.getAccessToken().getJWTToken());
        }

        @Override
        public void getAuthenticationDetails(AuthenticationContinuation authenticationContinuation, String userId) {
            // The API needs user sign-in credentials to continue
            AuthenticationDetails authenticationDetails = new AuthenticationDetails(emailField.toString(), passwordField.toString(), null);

            // Pass the user sign-in credentials to the continuation
            authenticationContinuation.setAuthenticationDetails(authenticationDetails);

            // Allow the sign-in to continue
            authenticationContinuation.continueTask();

        }

        @Override
        public void getMFACode(MultiFactorAuthenticationContinuation continuation) {

        }

        @Override
        public void authenticationChallenge(ChallengeContinuation continuation) {

        }
        @Override
        public void onFailure(Exception exception) {
            Log.i("ERROR:", exception.getMessage().toString());

        }
    };
}
04-15 18:32:09.618 5880-5880/com.ronone.securesender I/ERROR:: Unable to verify secret hash for client xxxxxxxxxxx (Service: AmazonCognitoIdentityProvider; Status Code: 400; Error Code: NotAuthorizedException; Request ID: 4eca8202-40db-11e8-a05e-217eccab3af8)

我在哪里可以找到这个秘密哈希密钥?感谢您提前提供任何帮助。

4

0 回答 0