Skip to content

Commit

Permalink
awspringgh-1246: support for public client operations
Browse files Browse the repository at this point in the history
  • Loading branch information
Forfend committed Dec 13, 2024
1 parent 8622414 commit e4dc185
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,20 +91,31 @@ public ForgotPasswordResponse resetPassword(String username) {
@Override
public ConfirmForgotPasswordResponse confirmResetPassword(String username, String confirmationCode,
String newPassword) {
ConfirmForgotPasswordRequest confirmForgotPasswordRequest = ConfirmForgotPasswordRequest.builder()
.clientId(clientId).username(username).password(newPassword).confirmationCode(confirmationCode)
.secretHash(CognitoUtils.calculateSecretHash(clientId, clientSecret, username)).build();
ConfirmForgotPasswordRequest.Builder confirmForgotPasswordRequestBuilder = ConfirmForgotPasswordRequest
.builder().clientId(clientId).username(username).password(newPassword)
.confirmationCode(confirmationCode);

if (this.clientSecret != null) {
confirmForgotPasswordRequestBuilder
.secretHash(CognitoUtils.calculateSecretHash(clientId, clientSecret, username));
}
ConfirmForgotPasswordRequest confirmForgotPasswordRequest = confirmForgotPasswordRequestBuilder.build();
return cognitoIdentityProviderClient.confirmForgotPassword(confirmForgotPasswordRequest);
}

@Override
public RespondToAuthChallengeResponse setPermanentPassword(String session, String username, String password) {
Map<String, String> resetPasswordParametersMap = new HashMap<>();
resetPasswordParametersMap.put(CognitoParameters.USERNAME_PARAM_NAME, username);
resetPasswordParametersMap.put(CognitoParameters.NEW_PASSWORD_PARAM_NAME, password);

if (this.clientSecret != null) {
resetPasswordParametersMap.put(CognitoParameters.SECRET_HASH_PARAM_NAME,
CognitoUtils.calculateSecretHash(clientId, clientSecret, username));
}
RespondToAuthChallengeRequest respondToAuthChallengeRequest = RespondToAuthChallengeRequest.builder()
.clientId(clientId).challengeName(ChallengeNameType.NEW_PASSWORD_REQUIRED).session(session)
.challengeResponses(Map.of(CognitoParameters.USERNAME_PARAM_NAME, username,
CognitoParameters.NEW_PASSWORD_PARAM_NAME, password, CognitoParameters.SECRET_HASH_PARAM_NAME,
CognitoUtils.calculateSecretHash(clientId, clientSecret, username)))
.build();
.challengeResponses(resetPasswordParametersMap).build();
return cognitoIdentityProviderClient.respondToAuthChallenge(respondToAuthChallengeRequest);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ LoginResponse login(@RequestBody LoginRequest loginRequest) {
AuthResult authResult = new AuthResult();
authResult.setStatus(Status.SET_PASSWORD);
loginResponse.setAuthResult(authResult);
return loginResponse;
}
AuthenticationResultType authenticationResultType = response.authenticationResult();
AuthResult authResult = new AuthResult();
Expand Down

0 comments on commit e4dc185

Please sign in to comment.