use of com.nexblocks.authguard.service.model.AuthResponseBO in project AuthGuard by AuthGuard.
the class RefreshToAccessTokenTest method exchangeInvalidToken.
@Test
void exchangeInvalidToken() {
// data
final String refreshToken = "refresh_token";
final AuthRequestBO authRequest = AuthRequestBO.builder().token(refreshToken).build();
// mock
Mockito.when(accountTokensRepository.getByToken(authRequest.getToken())).thenReturn(CompletableFuture.completedFuture(Optional.empty()));
// do
final Either<Exception, AuthResponseBO> actual = refreshToAccessToken.exchange(authRequest);
// assert
assertThat(actual.isLeft()).isTrue();
assertThat(actual.left().get()).isInstanceOf(ServiceAuthorizationException.class);
}
use of com.nexblocks.authguard.service.model.AuthResponseBO in project AuthGuard by AuthGuard.
the class RefreshToAccessTokenTest method exchange.
@Test
void exchange() {
// data
final String accountId = "account";
final String refreshToken = "refresh_token";
final AuthRequestBO authRequest = AuthRequestBO.builder().token(refreshToken).build();
final AccountTokenDO accountToken = AccountTokenDO.builder().token(refreshToken).associatedAccountId(accountId).expiresAt(OffsetDateTime.now().plusMinutes(1)).build();
final AccountBO account = AccountBO.builder().id(accountId).build();
final AuthResponseBO newTokens = AuthResponseBO.builder().token("new_token").refreshToken("new_refresh_token").build();
// mock
Mockito.when(accountTokensRepository.getByToken(authRequest.getToken())).thenReturn(CompletableFuture.completedFuture(Optional.of(accountToken)));
Mockito.when(accountsService.getById(accountId)).thenReturn(Optional.of(account));
Mockito.when(accessTokenProvider.generateToken(account, (TokenRestrictionsBO) null)).thenReturn(newTokens);
// do
final Either<Exception, AuthResponseBO> actual = refreshToAccessToken.exchange(authRequest);
// assert
assertThat(actual.isRight()).isTrue();
assertThat(actual.right().get()).isEqualTo(newTokens);
Mockito.verify(accountTokensRepository).deleteToken(refreshToken);
}
use of com.nexblocks.authguard.service.model.AuthResponseBO 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.AuthResponseBO in project AuthGuard by AuthGuard.
the class IdTokenProviderTest method generate.
@Test
void generate() {
final IdTokenProvider idTokenProvider = newProviderInstance(jwtConfig());
final AccountBO account = RANDOM.nextObject(AccountBO.class).withActive(true);
final AuthResponseBO tokens = idTokenProvider.generateToken(account);
assertThat(tokens).isNotNull();
assertThat(tokens.getToken()).isNotNull();
assertThat(tokens.getRefreshToken()).isNotNull();
assertThat(tokens.getToken()).isNotEqualTo(tokens.getRefreshToken());
verifyToken(tokens.getToken().toString(), account.getId(), null, null, null);
}
use of com.nexblocks.authguard.service.model.AuthResponseBO in project AuthGuard by AuthGuard.
the class JwtApiKeyProviderTest method generateTokenApp.
@Test
void generateTokenApp() {
final JtiProvider jtiProvider = Mockito.mock(JtiProvider.class);
final JwtApiKeyProvider tokenProvider = newProviderInstance(jtiProvider);
final String jti = "tokenId";
final AppBO app = RANDOM.nextObject(AppBO.class);
Mockito.when(jtiProvider.next()).thenReturn(jti);
final AuthResponseBO tokens = tokenProvider.generateToken(app);
assertThat(tokens).isNotNull();
assertThat(tokens.getToken()).isNotNull();
assertThat(tokens.getRefreshToken()).isNull();
verifyToken(tokens.getToken().toString(), app.getId(), jti);
}
Aggregations