Search in sources :

Example 1 with AuthResponseDTO

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"));
    }
}
Also used : RequestContextBO(com.nexblocks.authguard.service.model.RequestContextBO) AuthResponseDTO(com.nexblocks.authguard.api.dto.entities.AuthResponseDTO) AuthRequestDTO(com.nexblocks.authguard.api.dto.requests.AuthRequestDTO) Error(com.nexblocks.authguard.api.dto.entities.Error)

Example 2 with AuthResponseDTO

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);
}
Also used : RequestContextBO(com.nexblocks.authguard.service.model.RequestContextBO) AuthResponseDTO(com.nexblocks.authguard.api.dto.entities.AuthResponseDTO) OtpRequestDTO(com.nexblocks.authguard.api.dto.requests.OtpRequestDTO)

Example 3 with AuthResponseDTO

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);
}
Also used : ValidatableResponse(io.restassured.response.ValidatableResponse) AuthResponseDTO(com.nexblocks.authguard.api.dto.entities.AuthResponseDTO) AuthResponseBO(com.nexblocks.authguard.service.model.AuthResponseBO) AuthRequestDTO(com.nexblocks.authguard.api.dto.requests.AuthRequestDTO) AuthRequestBO(com.nexblocks.authguard.service.model.AuthRequestBO) Test(org.junit.jupiter.api.Test)

Aggregations

AuthResponseDTO (com.nexblocks.authguard.api.dto.entities.AuthResponseDTO)3 AuthRequestDTO (com.nexblocks.authguard.api.dto.requests.AuthRequestDTO)2 RequestContextBO (com.nexblocks.authguard.service.model.RequestContextBO)2 Error (com.nexblocks.authguard.api.dto.entities.Error)1 OtpRequestDTO (com.nexblocks.authguard.api.dto.requests.OtpRequestDTO)1 AuthRequestBO (com.nexblocks.authguard.service.model.AuthRequestBO)1 AuthResponseBO (com.nexblocks.authguard.service.model.AuthResponseBO)1 ValidatableResponse (io.restassured.response.ValidatableResponse)1 Test (org.junit.jupiter.api.Test)1