use of com.nexblocks.authguard.api.dto.entities.AuthResponseDTO in project AuthGuard by AuthGuard.
the class AuthRoute method authenticate.
public void authenticate(final Context context) {
final AuthRequestDTO authenticationRequest = authRequestBodyHandler.getValidated(context);
if (authenticationRequest.getDomain() != null && !ActorDomainVerifier.verifyActorDomain(context, authenticationRequest.getDomain())) {
return;
}
final RequestContextBO requestContext = RequestContextExtractor.extractWithoutIdempotentKey(context);
final Optional<AuthResponseDTO> tokens = authenticationService.authenticate(restMapper.toBO(authenticationRequest), requestContext).map(restMapper::toDTO);
if (tokens.isPresent()) {
context.json(tokens.get());
} else {
context.status(400).json(new Error("400", "Failed to authenticate user"));
}
}
use of com.nexblocks.authguard.api.dto.entities.AuthResponseDTO in project AuthGuard by AuthGuard.
the class OtpRoute method verify.
public void verify(final Context context) {
final OtpRequestDTO body = otpRequestBodyHandler.getValidated(context);
final RequestContextBO requestContext = RequestContextExtractor.extractWithoutIdempotentKey(context);
final AuthResponseDTO tokens = restMapper.toDTO(otpService.authenticate(body.getPasswordId(), body.getPassword(), requestContext));
context.json(tokens);
}
use of com.nexblocks.authguard.api.dto.entities.AuthResponseDTO in project AuthGuard by AuthGuard.
the class AuthRouteTest method authenticate.
@Test
void authenticate() {
final AuthRequestDTO requestDTO = randomObject(AuthRequestDTO.class);
final AuthRequestBO requestBO = restMapper.toBO(requestDTO);
final AuthResponseBO tokensBO = AuthResponseBO.builder().token("token").build();
final AuthResponseDTO tokensDTO = mapper().toDTO(tokensBO);
Mockito.when(authenticationService.authenticate(Mockito.eq(requestBO), Mockito.any())).thenReturn(Optional.of(tokensBO));
final ValidatableResponse httpResponse = given().body(requestDTO).post(url("authenticate")).then().statusCode(200).contentType(ContentType.JSON);
final AuthResponseDTO responseBody = httpResponse.extract().response().body().as(AuthResponseDTO.class);
assertThat(responseBody).isEqualTo(tokensDTO);
}
Aggregations