use of bio.terra.externalcreds.models.LinkedAccountWithPassportAndVisas in project terra-external-credentials-manager by DataBiosphere.
the class ProviderService method getRefreshedPassportsAndVisas.
private LinkedAccountWithPassportAndVisas getRefreshedPassportsAndVisas(LinkedAccount linkedAccount) {
var clientRegistration = providerClientCache.getProviderClient(linkedAccount.getProviderName()).orElseThrow(() -> new ExternalCredsException(String.format("Unable to find configs for the provider: %s", linkedAccount.getProviderName())));
var accessTokenResponse = oAuth2Service.authorizeWithRefreshToken(clientRegistration, new OAuth2RefreshToken(linkedAccount.getRefreshToken(), null));
// save the linked account with the new refresh token and extracted passport
var linkedAccountWithRefreshToken = Optional.ofNullable(accessTokenResponse.getRefreshToken()).map(refreshToken -> linkedAccountService.upsertLinkedAccount(linkedAccount.withRefreshToken(refreshToken.getTokenValue()))).orElse(linkedAccount);
// update the passport and visas
var userInfo = oAuth2Service.getUserInfo(clientRegistration, accessTokenResponse.getAccessToken());
return jwtUtils.enrichAccountWithPassportAndVisas(linkedAccountWithRefreshToken, userInfo);
}
use of bio.terra.externalcreds.models.LinkedAccountWithPassportAndVisas in project terra-external-credentials-manager by DataBiosphere.
the class ProviderServiceTest method createLinkedAccountWithOldVisa.
private LinkedAccountWithPassportAndVisas createLinkedAccountWithOldVisa(LinkedAccountService linkedAccountService) {
var visaNeedingVerification = TestUtils.createRandomVisa().withTokenType(TokenTypeEnum.access_token).withLastValidated(new Timestamp(Instant.now().minus(Duration.ofDays(50)).toEpochMilli()));
var savedLinkedAccountWithPassportAndVisa = linkedAccountService.upsertLinkedAccountWithPassportAndVisas(new LinkedAccountWithPassportAndVisas.Builder().linkedAccount(TestUtils.createRandomLinkedAccount()).passport(TestUtils.createRandomPassport()).visas(List.of(visaNeedingVerification)).build());
return savedLinkedAccountWithPassportAndVisa;
}
Aggregations