use of com.nexblocks.authguard.service.model.AuthResponseBO 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.AuthResponseBO in project AuthGuard by AuthGuard.
the class AuthRoute method exchange.
public void exchange(final Context context) {
final AuthRequestDTO authenticationRequest = authRequestBodyHandler.getValidated(context);
if (authenticationRequest.getDomain() != null && !ActorDomainVerifier.verifyActorDomain(context, authenticationRequest.getDomain())) {
return;
}
final String from = context.queryParam("from");
final String to = context.queryParam("to");
final RequestContextBO requestContext = RequestContextExtractor.extractWithoutIdempotentKey(context);
final AuthResponseBO tokens = exchangeService.exchange(restMapper.toBO(authenticationRequest), from, to, requestContext);
context.json(restMapper.toDTO(tokens));
}
use of com.nexblocks.authguard.service.model.AuthResponseBO in project AuthGuard by AuthGuard.
the class AuthRoute method clearToken.
@Override
public void clearToken(final Context context) {
final AuthRequestDTO authenticationRequest = authRequestBodyHandler.getValidated(context);
final String tokenType = context.queryParam("tokenType");
if (tokenType == null) {
context.status(400).json(new Error("400", "Missing 'tokenType' query parameter"));
} else {
final AuthResponseBO tokens = exchangeService.delete(restMapper.toBO(authenticationRequest), tokenType);
context.json(restMapper.toDTO(tokens));
}
}
use of com.nexblocks.authguard.service.model.AuthResponseBO in project AuthGuard by AuthGuard.
the class IdTokenProviderTest method generateEncrypted.
@Test
void generateEncrypted() {
final IdTokenProvider idTokenProvider = newProviderInstance(jwtConfigWithEncryption());
Mockito.when(tokenEncryptor.encryptAndEncode(Mockito.any())).thenAnswer(invocation -> Either.right("encrypted"));
final AccountBO account = RANDOM.nextObject(AccountBO.class).withActive(true);
final AuthResponseBO tokens = idTokenProvider.generateToken(account);
assertThat(tokens).isNotNull();
assertThat(tokens.getToken()).isEqualTo("encrypted");
assertThat(tokens.getRefreshToken()).isNotNull();
assertThat(tokens.getToken()).isNotEqualTo(tokens.getRefreshToken());
}
use of com.nexblocks.authguard.service.model.AuthResponseBO in project AuthGuard by AuthGuard.
the class AuthorizationCodeProviderTest method generateToken.
@Test
void generateToken() {
final AccountTokensRepository accountTokensRepository = Mockito.mock(AccountTokensRepository.class);
final AuthorizationCodeProvider authorizationCodeProvider = new AuthorizationCodeProvider(accountTokensRepository, new ServiceMapperImpl(), config());
final AccountBO account = AccountBO.builder().id("account-id").build();
final AuthResponseBO tokens = authorizationCodeProvider.generateToken(account);
assertThat(tokens.getType()).isEqualTo("authorizationCode");
assertThat(tokens.getToken()).isNotNull();
assertThat(tokens.getRefreshToken()).isNull();
final ArgumentCaptor<AccountTokenDO> argCaptor = ArgumentCaptor.forClass(AccountTokenDO.class);
Mockito.verify(accountTokensRepository, Mockito.times(1)).save(argCaptor.capture());
assertThat(argCaptor.getValue().getToken()).isEqualTo(tokens.getToken());
assertThat(argCaptor.getValue().getAssociatedAccountId()).isEqualTo(account.getId());
assertThat(argCaptor.getValue().getExpiresAt()).isAfter(OffsetDateTime.now()).isBefore(OffsetDateTime.now().plus(Duration.ofMinutes(6)));
}
Aggregations