在哪里识别秘密哈希密钥



我正在尝试创建一个简单的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)

在哪里可以找到此秘密哈希密钥?提前感谢您的任何帮助。

请参阅此链接。密钥哈希需要使用用户名、clientId 和 clientSecretId 进行计算。链接中提供了 python 实现。将其翻译为您的首选语言。

https://aws.amazon.com/premiumsupport/knowledge-center/cognito-unable-to-verify-secret-hash/

最新更新