Search in sources :

Example 6 with IDToken

use of com.microsoft.identity.common.internal.providers.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();
}
Also used : IdToken(com.google.auth.oauth2.IdToken) Instant(java.time.Instant) IOException(java.io.IOException) IdTokenCredentials(com.google.auth.oauth2.IdTokenCredentials)

Example 7 with IDToken

use of com.microsoft.identity.common.internal.providers.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"));
}
Also used : IdToken(com.google.auth.oauth2.IdToken) JsonWebSignature(com.google.api.client.json.webtoken.JsonWebSignature) GoogleCredentials(com.google.auth.oauth2.GoogleCredentials) IdTokenCredentials(com.google.auth.oauth2.IdTokenCredentials) Test(org.junit.jupiter.api.Test)

Example 8 with IDToken

use of com.microsoft.identity.common.internal.providers.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);
    }
}
Also used : IdToken(com.google.auth.oauth2.IdToken) IOException(java.io.IOException)

Example 9 with IDToken

use of com.microsoft.identity.common.internal.providers.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"));
}
Also used : IdToken(com.google.auth.oauth2.IdToken) JsonWebSignature(com.google.api.client.json.webtoken.JsonWebSignature) GoogleCredentials(com.google.auth.oauth2.GoogleCredentials) IdTokenCredentials(com.google.auth.oauth2.IdTokenCredentials) Test(org.junit.jupiter.api.Test)

Example 10 with IDToken

use of com.microsoft.identity.common.internal.providers.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;
}
Also used : ServiceException(com.microsoft.identity.common.exception.ServiceException) IDToken(com.microsoft.identity.common.internal.providers.oauth2.IDToken)

Aggregations

IDToken (com.microsoft.identity.common.internal.providers.oauth2.IDToken)8 ServiceException (com.microsoft.identity.common.exception.ServiceException)7 IdToken (com.google.auth.oauth2.IdToken)4 ClientInfo (com.microsoft.identity.common.internal.providers.microsoft.azureactivedirectory.ClientInfo)4 IdTokenCredentials (com.google.auth.oauth2.IdTokenCredentials)3 Nullable (androidx.annotation.Nullable)2 JsonWebSignature (com.google.api.client.json.webtoken.JsonWebSignature)2 GoogleCredentials (com.google.auth.oauth2.GoogleCredentials)2 IOException (java.io.IOException)2 Test (org.junit.jupiter.api.Test)2 JsonObject (com.google.gson.JsonObject)1 ClientException (com.microsoft.identity.common.exception.ClientException)1 BrokerResult (com.microsoft.identity.common.internal.broker.BrokerResult)1 IdTokenRecord (com.microsoft.identity.common.internal.dto.IdTokenRecord)1 MicrosoftRefreshToken (com.microsoft.identity.common.internal.providers.microsoft.MicrosoftRefreshToken)1 AzureActiveDirectoryAccount (com.microsoft.identity.common.internal.providers.microsoft.azureactivedirectory.AzureActiveDirectoryAccount)1 MicrosoftStsAccount (com.microsoft.identity.common.internal.providers.microsoft.microsoftsts.MicrosoftStsAccount)1 MsalBrokerResultAdapter (com.microsoft.identity.common.internal.result.MsalBrokerResultAdapter)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1