use of com.nexblocks.authguard.service.model.RequestContextBO 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.service.model.RequestContextBO 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.service.model.RequestContextBO in project AuthGuard by AuthGuard.
the class PasswordlessRoute method verify.
public void verify(final Context context) {
final PasswordlessRequestDTO request = passwordlessRequestBodyHandler.getValidated(context);
final RequestContextBO requestContext = RequestContextExtractor.extractWithoutIdempotentKey(context);
final AuthResponseBO generatedTokens = passwordlessService.authenticate(request.getToken(), requestContext);
context.json(generatedTokens);
}
use of com.nexblocks.authguard.service.model.RequestContextBO in project AuthGuard by AuthGuard.
the class OtpServiceImplTest method authenticate.
@Test
void authenticate() {
final OtpConfig otpConfig = OtpConfig.builder().generateToken("accessToken").build();
setup(otpConfig);
final OneTimePasswordDO otp = random.nextObject(OneTimePasswordDO.class);
final AuthResponseBO tokens = random.nextObject(AuthResponseBO.class);
final String otpToken = otp.getId() + ":" + otp.getPassword();
final AuthRequestBO authRequest = AuthRequestBO.builder().token(otpToken).build();
final RequestContextBO requestContext = RequestContextBO.builder().build();
Mockito.when(mockExchangeService.exchange(authRequest, "otp", otpConfig.getGenerateToken(), requestContext)).thenReturn(tokens);
final AuthResponseBO generated = otpService.authenticate(otp.getId(), otp.getPassword(), requestContext);
assertThat(generated).isEqualTo(tokens);
}
use of com.nexblocks.authguard.service.model.RequestContextBO in project AuthGuard by AuthGuard.
the class AccountsApiTest method create.
@Test
void create() {
final CreateAccountRequestDTO requestDTO = CreateAccountRequestDTO.builder().externalId("external").email(AccountEmailDTO.builder().email("email@server.com").build()).domain("main").build();
final RequestContextBO requestContext = RequestContextBO.builder().idempotentKey(UUID.randomUUID().toString()).build();
final AccountBO accountBO = mapper().toBO(requestDTO);
final AccountBO serviceResponse = accountBO.withId(UUID.randomUUID().toString());
Mockito.when(accountsService.create(Mockito.eq(accountBO), Mockito.any())).thenReturn(serviceResponse);
LOG.info("Request {}", requestDTO);
final ValidatableResponse httpResponse = given().body(requestDTO).contentType(ContentType.JSON).header(IdempotencyHeader.HEADER_NAME, requestContext.getIdempotentKey()).post(url()).then().statusCode(201).contentType(ContentType.JSON);
final AccountDTO response = httpResponse.extract().response().getBody().as(AccountDTO.class);
assertThat(response).isEqualToIgnoringGivenFields(requestDTO, "id", "deleted", "createdAt", "lastModified", "social", "identityProvider");
assertThat(response.getId()).isEqualTo(serviceResponse.getId());
}
Aggregations