use of com.nexblocks.authguard.dal.model.AccountTokenDO in project AuthGuard by AuthGuard.
the class SmsPasswordlessSubscriberTest method onValidMessageNoPhoneNumber.
@Test
void onValidMessageNoPhoneNumber() {
final AccountTokenDO accountToken = AccountTokenDO.builder().token("token").build();
final AccountBO account = AccountBO.builder().build();
final PasswordlessMessageBody messageBody = new PasswordlessMessageBody(accountToken, account);
final Message message = Messages.passwordlessGenerated(messageBody);
smsPasswordlessSubscriber.onMessage(message);
Mockito.verify(smsProvider, Mockito.never()).send(Mockito.any());
}
use of com.nexblocks.authguard.dal.model.AccountTokenDO in project AuthGuard by AuthGuard.
the class AccessTokenProvider method storeRefreshToken.
private void storeRefreshToken(final String accountId, final String refreshToken, final TokenRestrictionsBO tokenRestrictions) {
final AccountTokenDO accountToken = AccountTokenDO.builder().id(ID.generate()).token(refreshToken).associatedAccountId(accountId).expiresAt(refreshTokenExpiry()).tokenRestrictions(// Mapstruct already checks for null
serviceMapper.toDO(tokenRestrictions)).build();
accountTokensRepository.save(accountToken).join();
}
use of com.nexblocks.authguard.dal.model.AccountTokenDO in project AuthGuard by AuthGuard.
the class AuthorizationCodeProvider method generateToken.
@Override
public AuthResponseBO generateToken(final AccountBO account, final TokenRestrictionsBO restrictions, final TokenOptionsBO options) {
final String code = random.base64(config.getRandomSize());
final AccountTokenDO accountToken = AccountTokenDO.builder().token(TOKEN_TYPE).id(ID.generate()).token(code).associatedAccountId(account.getId()).expiresAt(OffsetDateTime.now().plus(tokenTtl)).tokenRestrictions(serviceMapper.toDO(restrictions)).build();
accountTokensRepository.save(accountToken);
return AuthResponseBO.builder().type("authorizationCode").token(code).entityType(EntityType.ACCOUNT).entityId(account.getId()).build();
}
use of com.nexblocks.authguard.dal.model.AccountTokenDO in project AuthGuard by AuthGuard.
the class AccessTokenProviderTest method newProviderInstance.
private AccessTokenProvider newProviderInstance(final JwtConfig jwtConfig, final StrategyConfig strategyConfig) {
jtiProvider = Mockito.mock(JtiProvider.class);
accountTokensRepository = Mockito.mock(AccountTokensRepository.class);
tokenEncryptor = Mockito.mock(TokenEncryptorAdapter.class);
Mockito.when(accountTokensRepository.save(Mockito.any())).thenAnswer(invocation -> {
final AccountTokenDO arg = invocation.getArgument(0);
return CompletableFuture.completedFuture(arg);
});
return new AccessTokenProvider(accountTokensRepository, jwtConfig, strategyConfig, jtiProvider, tokenEncryptor, new ServiceMapperImpl());
}
use of com.nexblocks.authguard.dal.model.AccountTokenDO in project AuthGuard by AuthGuard.
the class VerificationSubscriber method doSendEmails.
private void doSendEmails(final VerificationRequestBO verificationRequest) {
final AccountBO account = verificationRequest.getAccount();
verificationRequest.getEmails().forEach(email -> {
if (email == null) {
LOG.warn("Email is null. Skipping.");
} else if (email.isVerified()) {
LOG.warn("Email is already verified. Skipping.");
} else {
final String token = generateVerificationString();
final AccountTokenDO accountToken = AccountTokenDO.builder().expiresAt(OffsetDateTime.now().plus(tokenTtl)).associatedAccountId(account.getId()).token(token).additionalInformation(Collections.singletonMap("email", email.getEmail())).build();
accountTokensRepository.save(accountToken);
final ImmutableEmail email1 = ImmutableEmail.builder().template(EMAIL_TEMPLATE).to(email.getEmail()).putParameters("token", token).build();
emailProvider.send(email1);
LOG.info("Sent a verification email");
}
});
}
Aggregations