Automate login of application that uses AWS cognito with CUSTOM_AUTH authentication flow

70 views Asked by At

I'm trying to automate the login of my application but it uses AWS cognito service for authentication and the auth flow is CUSTOM_AUTH. Is it possible to automate this login using the initiateAuth if I just have the username, clientId and user pool id along with the AWS java SDK without the access key and client secret?I'm trying to get the accessToken and ID token as the the response of initiateAuth.

Tried out the below code but getting error 'com.amazonaws.services.cognitoidp.model.UserLambdaValidationException: DefineAuthChallenge failed with error Cannot read properties of undefined (reading 'challengeName')'

final String clientId = "clientId";
    final String region = "region";
    final String username = "username";
    final String password = "pwd";

    AWSCognitoIdentityProvider cognitoClient = AWSCognitoIdentityProviderClientBuilder.standard()
            .withRegion(region)
            .build();
    final Map<String, String> authParams = new HashMap<>();
    authParams.put("USERNAME", username);
    authParams.put("PASSWORD", password);
    final InitiateAuthRequest authRequest = new InitiateAuthRequest();
    authRequest.withAuthFlow(AuthFlowType.CUSTOM_AUTH)
            .withClientId(clientId)
            .withAuthParameters(authParams);
    InitiateAuthResult result = cognitoClient.initiateAuth(authRequest);
0

There are 0 answers