use of com.google.auth.oauth2.IdToken in project flytekit-java by flyteorg.
the class GoogleAuthHelper method getIdTokenFromIdTokenProvider.
private Token getIdTokenFromIdTokenProvider(String targetAudience) throws IOException {
LOG.info("Fetching token from provider");
IdTokenCredentials idTokenCredentials = IdTokenCredentials.newBuilder().setIdTokenProvider((IdTokenProvider) credentials).setTargetAudience(targetAudience).build();
idTokenCredentials.refresh();
IdToken idToken = idTokenCredentials.getIdToken();
if (idToken == null || idToken.getTokenValue() == null) {
throw new IOException("Couldn't get id token for credential");
}
Instant expiryAt = idToken.getExpirationTime().toInstant();
return Token.builder().accessToken(idToken.getTokenValue()).expiry(expiryAt).tokenType("Bearer").build();
}
use of com.google.auth.oauth2.IdToken in project google-auth-library-java by google.
the class FTServiceAccountCredentialsTest method AudienceSetNoScopeTest.
// TODO: add Storage case
@Test
void AudienceSetNoScopeTest() throws Exception {
final GoogleCredentials credentials = GoogleCredentials.getApplicationDefault();
IdTokenCredentials tokenCredential = IdTokenCredentials.newBuilder().setIdTokenProvider((IdTokenProvider) credentials).setTargetAudience(cloudTasksUrl).build();
assertNull(tokenCredential.getIdToken());
tokenCredential.refresh();
IdToken idToken = tokenCredential.getIdToken();
assertNotNull(idToken);
assertTrue(idToken.getExpirationTime().getTime() > System.currentTimeMillis());
JsonWebSignature jws = JsonWebSignature.parse(GsonFactory.getDefaultInstance(), idToken.getTokenValue());
assertEquals(cloudTasksUrl, jws.getPayload().get("aud"));
assertEquals("https://accounts.google.com", jws.getPayload().get("iss"));
}
use of com.google.auth.oauth2.IdToken in project amplify-android by aws-amplify.
the class MultiAuthSyncEngineInstrumentationTest method oidcLogin.
// The following link was helpful in finding the right setup
// https://github.com/googleapis/google-auth-library-java#google-auth-library-oauth2-http
private void oidcLogin() {
try {
IdToken idToken = googleServiceAccount.idTokenWithAudience(AUDIENCE, Collections.emptyList());
token.set(idToken.getTokenValue());
} catch (IOException exception) {
LOG.warn("An error occurred while trying to authenticate against OIDC provider", exception);
}
}
use of com.google.auth.oauth2.IdToken in project google-auth-library-java by googleapis.
the class FTServiceAccountCredentialsTest method AudienceSetNoScopeTest.
// TODO: add Storage case
@Test
void AudienceSetNoScopeTest() throws Exception {
final GoogleCredentials credentials = GoogleCredentials.getApplicationDefault();
IdTokenCredentials tokenCredential = IdTokenCredentials.newBuilder().setIdTokenProvider((IdTokenProvider) credentials).setTargetAudience(cloudTasksUrl).build();
assertNull(tokenCredential.getIdToken());
tokenCredential.refresh();
IdToken idToken = tokenCredential.getIdToken();
assertNotNull(idToken);
assertTrue(idToken.getExpirationTime().getTime() > System.currentTimeMillis());
JsonWebSignature jws = JsonWebSignature.parse(GsonFactory.getDefaultInstance(), idToken.getTokenValue());
assertEquals(cloudTasksUrl, jws.getPayload().get("aud"));
assertEquals("https://accounts.google.com", jws.getPayload().get("iss"));
}
use of com.google.auth.oauth2.IdToken in project microsoft-authentication-library-common-for-android by AzureAD.
the class AzureActiveDirectoryOAuth2Strategy method createAccount.
/**
* Stubbed out for now, but should create a new AzureActiveDirectory account.
* Should accept a parameter (TokenResponse) for producing that user
*
* @return
*/
@Override
public AzureActiveDirectoryAccount createAccount(@NonNull final AzureActiveDirectoryTokenResponse response) {
final String methodName = "createAccount";
IDToken idToken = null;
ClientInfo clientInfo = null;
try {
Logger.info(TAG, "Constructing IDToken from response");
idToken = new IDToken(response.getIdToken());
Logger.info(TAG, "Constructing ClientInfo from response");
clientInfo = new ClientInfo(response.getClientInfo());
} catch (ServiceException ccse) {
Logger.error(TAG + ":" + methodName, "Failed to construct IDToken or ClientInfo", null);
Logger.errorPII(TAG + ":" + methodName, "Failed with Exception", ccse);
throw new RuntimeException();
}
final AzureActiveDirectoryAccount account = new AzureActiveDirectoryAccount(idToken, clientInfo);
Logger.info(TAG, "Account created");
Logger.infoPII(TAG, account.toString());
return account;
}
Aggregations