use of org.glassfish.jersey.client.oauth1.AccessToken in project terra-workspace-manager by DataBiosphere.
the class ClientTestUtils method getClientForTestUser.
/**
* Build the Workspace Manager API client object for the given test user and server
* specifications. The test user's token is always refreshed
*
* @param testUser the test user whose credentials are supplied to the API client object
* @param server the server we are testing against
* @return the API client object for this user
*/
public static ApiClient getClientForTestUser(TestUserSpecification testUser, ServerSpecification server) throws IOException {
AccessToken accessToken = null;
// this is useful if the caller wants to make ONLY unauthenticated calls
if (testUser != null) {
logger.debug("Fetching credentials and building Workspace Manager ApiClient object for test user: {}", testUser.name);
GoogleCredentials userCredential = AuthenticationUtils.getDelegatedUserCredential(testUser, TEST_USER_SCOPES);
accessToken = AuthenticationUtils.getAccessToken(userCredential);
}
return buildClient(accessToken, server);
}
use of org.glassfish.jersey.client.oauth1.AccessToken in project terra-workspace-manager by DataBiosphere.
the class SamClientUtils method getSamApiClient.
private static ApiClient getSamApiClient(TestUserSpecification testUser, ServerSpecification server) throws Exception {
AccessToken accessToken = null;
// this is useful if the caller wants to make ONLY unauthenticated calls
if (testUser != null) {
logger.debug("Fetching credentials and building Sam ApiClient object for test user: {}", testUser.name);
GoogleCredentials userCredential = AuthenticationUtils.getDelegatedUserCredential(testUser, ClientTestUtils.TEST_USER_SCOPES);
accessToken = AuthenticationUtils.getAccessToken(userCredential);
}
return buildSamClient(accessToken, server);
}
use of org.glassfish.jersey.client.oauth1.AccessToken in project airy by airyhq.
the class Api method sendMessage.
public void sendMessage(final String conversationId, JsonNode sendMessagePayload) throws Exception {
String reqUrl = String.format(requestTemplate, conversationId);
final byte[] serializedServiceAccount = objectMapper.writeValueAsString(serviceAccount).getBytes();
GoogleCredentials credentials = GoogleCredentials.fromStream(new ByteArrayInputStream(serializedServiceAccount)).createScoped(List.of("https://www.googleapis.com/auth/businessmessages"));
credentials.refreshIfExpired();
AccessToken token = credentials.getAccessToken();
restTemplate.postForEntity(reqUrl, new HttpEntity<>(sendMessagePayload, getHeaders(token.getTokenValue())), String.class);
}
use of org.glassfish.jersey.client.oauth1.AccessToken in project gcs-uploader by GoogleCloudPlatform.
the class AuthConfig method updateToken.
public void updateToken(final AuthConfigListener listener) {
RestTemplate restTemplate = new RestTemplate();
HttpHeaders headers = new HttpHeaders();
headers.add("x-content-refresh-token", authInfo.getRefreshToken());
headers.setContentType(MediaType.APPLICATION_JSON);
headers.setContentLength(0L);
try {
RequestEntity requestEntity = new RequestEntity(headers, HttpMethod.POST, new URI(envConfig.getAuthEndpoint() + "/auth/renew_access_token"));
ResponseEntity<AuthInfo> authInfoResponse = restTemplate.exchange(requestEntity, AuthInfo.class);
AuthInfo newAuthInfo = authInfoResponse.getBody();
newAuthInfo.setRefreshToken(authInfo.getRefreshToken());
authInfo = newAuthInfo;
credentials = GoogleCredentials.create(new AccessToken(authInfo.getAccessToken(), new Date(authInfo.getExpirationSeconds() * 1000)));
buildStorage();
validateAuthorization();
if (listener != null) {
listener.authInfoUpdated();
}
} catch (Exception e) {
e.printStackTrace();
if (listener != null) {
listener.authInfoError(e);
}
}
}
use of org.glassfish.jersey.client.oauth1.AccessToken in project java-bigtable by googleapis.
the class BigtableChannelPrimerTest method testErrorsAreLoggedForBasic.
@Test
public void testErrorsAreLoggedForBasic() {
BigtableChannelPrimer basicPrimer = BigtableChannelPrimer.create(OAuth2Credentials.create(new AccessToken(TOKEN_VALUE, null)), "fake-project", "fake-instance", "fake-app-profile", ImmutableList.<String>of());
ManagedChannel channel = Mockito.mock(ManagedChannel.class, new ThrowsException(new UnsupportedOperationException()));
primer.primeChannel(channel);
assertThat(logHandler.logs).hasSize(1);
for (LogRecord log : logHandler.logs) {
assertThat(log.getMessage()).contains("Unexpected");
}
}
Aggregations