Zombies
Zombies

Reputation: 25902

Why do I need to provide AWS Credentials when using the Cognito SDK?

My Java app is using AWS Cognito user pools. It uses the Amazon SDK to sign users in. EG:

        Map<String, String> authParams = new HashMap<>();
        authParams.put("USERNAME", email);
        authParams.put("PASSWORD", StringUtils.SPACE);

        AdminInitiateAuthRequest authRequest = new AdminInitiateAuthRequest()
            .withAuthFlow(AuthFlowType.ADMIN_NO_SRP_AUTH)
            .withAuthParameters(authParams)
            .withClientId(clientId)
            .withUserPoolId(poolId);

        AdminInitiateAuthResult result = cognitoClient.adminInitiateAuth(authRequest);

This code above will not work without AWS access credentials. Why though? I just want to access the AWS Cognito user pool. Is it absolutely required that I need to pass in AWS credentials into the Java app? Trying to avoid having to either version AWS credentials or manually configure them (or set up some auto-configure mechanism).

Upvotes: 2

Views: 661

Answers (1)

jarmod
jarmod

Reputation: 78793

You're using adminInitiateAuth, which is a server-side authentication flow. This is how your credentialed backend would authenticate a user.

For client-side authentication flow, you should use initiateAuth, not adminInitiateAuth.

See User Pool Authentication Flow in the Developer Guide.

Upvotes: 4

Related Questions