use of com.nexblocks.authguard.external.sms.ImmutableTextMessage in project AuthGuard by AuthGuard.
the class SmsPasswordlessSubscriber method sendEmail.
private void sendEmail(final AccountBO account, final AccountTokenDO accountToken) {
if (account.getPhoneNumber() != null) {
final ImmutableMap.Builder<String, String> parameters = ImmutableMap.builder();
if (account.getFirstName() != null) {
parameters.put("firstName", account.getFirstName());
}
if (account.getLastName() != null) {
parameters.put("lastName", account.getLastName());
}
final ImmutableTextMessage sms = ImmutableTextMessage.builder().to(account.getPhoneNumber().getNumber()).parameters(parameters.put("token", accountToken.getToken()).build()).build();
smsProvider.send(sms);
} else {
LOG.error("A passwordless token was generated for an account without a phone number. Account: {}, token ID: {}", account.getId(), accountToken.getId());
}
}
use of com.nexblocks.authguard.external.sms.ImmutableTextMessage in project AuthGuard by AuthGuard.
the class SmsOtpSubscriberTest method onValidMessage.
@Test
void onValidMessage() {
final OneTimePasswordBO otp = OneTimePasswordBO.builder().password("password").build();
final AccountBO account = AccountBO.builder().phoneNumber(PhoneNumberBO.builder().number("+178945632").build()).firstName("first").lastName("second").build();
final OtpMessageBody messageBody = new OtpMessageBody(otp, account, true, false);
final Message message = Messages.otpGenerated(messageBody);
final ImmutableTextMessage expectedEmail = ImmutableTextMessage.builder().to(account.getPhoneNumber().getNumber()).parameters(ImmutableMap.of("password", otp.getPassword(), "firstName", account.getFirstName(), "lastName", account.getLastName())).build();
otpSubscriber.onMessage(message);
final ArgumentCaptor<ImmutableTextMessage> sentSmsCaptor = ArgumentCaptor.forClass(ImmutableTextMessage.class);
Mockito.verify(smsProvider).send(sentSmsCaptor.capture());
assertThat(sentSmsCaptor.getValue()).isEqualTo(expectedEmail);
}
use of com.nexblocks.authguard.external.sms.ImmutableTextMessage in project AuthGuard by AuthGuard.
the class SmsPasswordlessSubscriberTest method onValidMessage.
@Test
void onValidMessage() {
final AccountTokenDO accountToken = AccountTokenDO.builder().token("token").build();
final AccountBO account = AccountBO.builder().phoneNumber(PhoneNumberBO.builder().number("+178945632").build()).firstName("first").lastName("second").build();
final PasswordlessMessageBody messageBody = new PasswordlessMessageBody(accountToken, account);
final Message message = Messages.passwordlessGenerated(messageBody);
final ImmutableTextMessage expectedSms = ImmutableTextMessage.builder().to(account.getPhoneNumber().getNumber()).parameters(ImmutableMap.of("token", accountToken.getToken(), "firstName", account.getFirstName(), "lastName", account.getLastName())).build();
smsPasswordlessSubscriber.onMessage(message);
final ArgumentCaptor<ImmutableTextMessage> sentSmsCaptor = ArgumentCaptor.forClass(ImmutableTextMessage.class);
Mockito.verify(smsProvider).send(sentSmsCaptor.capture());
assertThat(sentSmsCaptor.getValue()).isEqualTo(expectedSms);
}
use of com.nexblocks.authguard.external.sms.ImmutableTextMessage in project AuthGuard by AuthGuard.
the class SmsOtpSubscriber method sendEmail.
private void sendEmail(final AccountBO account, final OneTimePasswordBO otp) {
if (account.getPhoneNumber() != null) {
final ImmutableMap.Builder<String, String> parameters = ImmutableMap.builder();
if (account.getFirstName() != null) {
parameters.put("firstName", account.getFirstName());
}
if (account.getLastName() != null) {
parameters.put("lastName", account.getLastName());
}
final ImmutableTextMessage sms = ImmutableTextMessage.builder().to(account.getPhoneNumber().getNumber()).parameters(parameters.put("password", otp.getPassword()).build()).build();
smsProvider.send(sms);
} else {
LOG.error("An email OTP was generated for an account without a phone number. Account: {}, password ID: {}", account.getId(), otp.getId());
}
}
Aggregations