use of com.microsoft.identity.common.internal.providers.oauth2.AccessToken in project spring-vault by spring-projects.
the class GcpIamCredentialsAuthenticationUnitTests method shouldCreateNewGcpIamObjectInstance.
@Test
void shouldCreateNewGcpIamObjectInstance() {
PrivateKey privateKeyMock = mock(PrivateKey.class);
ServiceAccountCredentials credential = (ServiceAccountCredentials) ServiceAccountCredentials.newBuilder().setClientEmail("hello@world").setProjectId("foobar").setPrivateKey(privateKeyMock).setPrivateKeyId("key-id").setAccessToken(new AccessToken("foobar", Date.from(Instant.now().plus(1, ChronoUnit.DAYS)))).build();
GcpIamCredentialsAuthenticationOptions options = GcpIamCredentialsAuthenticationOptions.builder().role("dev-role").credentials(credential).build();
new GcpIamCredentialsAuthentication(options, this.restTemplate);
}
use of com.microsoft.identity.common.internal.providers.oauth2.AccessToken in project spring-vault by spring-projects.
the class GcpIamCredentialsAuthenticationUnitTests method shouldLogin.
@Test
void shouldLogin() {
this.serverCall = ((request, responseObserver) -> {
SignJwtResponse signJwtResponse = SignJwtResponse.newBuilder().setSignedJwt("my-jwt").setKeyId("key-id").build();
responseObserver.onNext(signJwtResponse);
responseObserver.onCompleted();
});
this.mockRest.expect(requestTo("/auth/gcp/login")).andExpect(method(HttpMethod.POST)).andExpect(jsonPath("$.role").value("dev-role")).andExpect(jsonPath("$.jwt").value("my-jwt")).andRespond(withSuccess().contentType(MediaType.APPLICATION_JSON).body("{" + "\"auth\":{\"client_token\":\"my-token\", \"renewable\": true, \"lease_duration\": 10}" + "}"));
PrivateKey privateKeyMock = mock(PrivateKey.class);
ServiceAccountCredentials credential = (ServiceAccountCredentials) ServiceAccountCredentials.newBuilder().setClientEmail("hello@world").setProjectId("foobar").setPrivateKey(privateKeyMock).setPrivateKeyId("key-id").setAccessToken(new AccessToken("foobar", Date.from(Instant.now().plus(1, ChronoUnit.DAYS)))).build();
GcpIamCredentialsAuthenticationOptions options = GcpIamCredentialsAuthenticationOptions.builder().role("dev-role").credentials(credential).build();
GcpIamCredentialsAuthentication authentication = new GcpIamCredentialsAuthentication(options, this.restTemplate, FixedTransportChannelProvider.create(GrpcTransportChannel.create(managedChannel)));
VaultToken login = authentication.login();
assertThat(login).isInstanceOf(LoginToken.class);
assertThat(login.getToken()).isEqualTo("my-token");
LoginToken loginToken = (LoginToken) login;
assertThat(loginToken.isRenewable()).isTrue();
assertThat(loginToken.getLeaseDuration()).isEqualTo(Duration.ofSeconds(10));
}
use of com.microsoft.identity.common.internal.providers.oauth2.AccessToken in project jib by GoogleContainerTools.
the class CredentialRetrieverFactoryTest method setUp.
@Before
public void setUp() throws CredentialHelperUnhandledServerUrlException, CredentialHelperNotFoundException, IOException {
Mockito.when(mockDockerCredentialHelperFactory.create(Mockito.anyString(), Mockito.any(Path.class), Mockito.anyMap())).thenReturn(mockDockerCredentialHelper);
Mockito.when(mockDockerCredentialHelper.retrieve()).thenReturn(FAKE_CREDENTIALS);
Mockito.when(mockGoogleCredentials.getAccessToken()).thenReturn(new AccessToken("my-token", null));
}
use of com.microsoft.identity.common.internal.providers.oauth2.AccessToken in project dialogflow-transactions-java by actions-on-google.
the class TransactionsApp method sendOrderUpdate.
private static void sendOrderUpdate(String orderId) throws IOException {
// Setup service account credentials
String serviceAccountKeyFileName = "service-account.json";
// Setup service account credentials
String serviceAccountFile = TransactionsApp.class.getClassLoader().getResource(serviceAccountKeyFileName).getFile();
InputStream actionsApiServiceAccount = new FileInputStream(serviceAccountFile);
ServiceAccountCredentials serviceAccountCredentials = (ServiceAccountCredentials) ServiceAccountCredentials.fromStream(actionsApiServiceAccount).createScoped(Collections.singleton("https://www.googleapis.com/auth/actions.order.developer"));
AccessToken token = serviceAccountCredentials.refreshAccessToken();
// Setup request with headers
HttpPatch request = new HttpPatch("https://actions.googleapis.com/v3/orders/" + orderId);
request.setHeader("Content-type", "application/json");
request.setHeader("Authorization", "Bearer " + token.getTokenValue());
// Create order update
FieldMask fieldMask = FieldMask.newBuilder().addAllPaths(Arrays.asList("lastUpdateTime", "purchase.status", "purchase.userVisibleStatusLabel")).build();
OrderUpdateV3 orderUpdate = new OrderUpdateV3().setOrder(new OrderV3().setMerchantOrderId(orderId).setLastUpdateTime(Instant.now().toString()).setPurchase(new PurchaseOrderExtension().setStatus("DELIVERED").setUserVisibleStatusLabel("Order delivered."))).setUpdateMask(FieldMaskUtil.toString(fieldMask)).setReason("Order status was updated to delivered.");
// Setup JSON body containing order update
JsonParser parser = new JsonParser();
JsonObject orderUpdateJson = parser.parse(new Gson().toJson(orderUpdate)).getAsJsonObject();
JsonObject body = new JsonObject();
body.add("orderUpdate", orderUpdateJson);
JsonObject header = new JsonObject();
header.addProperty("isInSandbox", true);
body.add("header", header);
StringEntity entity = new StringEntity(body.toString());
entity.setContentType(ContentType.APPLICATION_JSON.getMimeType());
request.setEntity(entity);
// Make request
HttpClient httpClient = HttpClientBuilder.create().build();
HttpResponse response = httpClient.execute(request);
LOGGER.info(response.getStatusLine().getStatusCode() + " " + response.getStatusLine().getReasonPhrase());
}
use of com.microsoft.identity.common.internal.providers.oauth2.AccessToken in project google-auth-library-java by googleapis.
the class AppEngineCredentials method refreshAccessToken.
/**
* Refresh the access token by getting it from the App Identity service
*/
@Override
public AccessToken refreshAccessToken() throws IOException {
if (createScopedRequired()) {
throw new IOException("AppEngineCredentials requires createScoped call before use.");
}
GetAccessTokenResult accessTokenResponse = appIdentityService.getAccessToken(scopes);
String accessToken = accessTokenResponse.getAccessToken();
Date expirationTime = accessTokenResponse.getExpirationTime();
return new AccessToken(accessToken, expirationTime);
}
Aggregations