Search in sources :

Example 11 with IdToken

use of com.google.auth.oauth2.IdToken in project microsoft-authentication-library-common-for-android by AzureAD.

the class SchemaUtil method getCredentialTypeFromVersion.

public static String getCredentialTypeFromVersion(@Nullable final String idTokenString) {
    final String methodName = "getCredentialTypeFromVersion";
    // Default is v2
    String idTokenVersion = CredentialType.IdToken.name();
    if (!TextUtils.isEmpty(idTokenString)) {
        IDToken idToken;
        try {
            idToken = new IDToken(idTokenString);
            final Map<String, ?> idTokenClaims = idToken.getTokenClaims();
            final String aadVersion = (String) idTokenClaims.get(AuthenticationConstants.OAuth2.AAD_VERSION);
            if (AuthenticationConstants.OAuth2.AAD_VERSION_V1.equalsIgnoreCase(aadVersion)) {
                idTokenVersion = CredentialType.V1IdToken.name();
            }
        } catch (ServiceException e) {
            Logger.warn(TAG + ":" + methodName, EXCEPTION_CONSTRUCTING_IDTOKEN + e.getMessage());
        }
    }
    return idTokenVersion;
}
Also used : ServiceException(com.microsoft.identity.common.exception.ServiceException) IDToken(com.microsoft.identity.common.internal.providers.oauth2.IDToken)

Example 12 with IdToken

use of com.google.auth.oauth2.IdToken in project microsoft-authentication-library-common-for-android by AzureAD.

the class SchemaUtil method getIdentityProvider.

public static String getIdentityProvider(final String idTokenString) {
    final String methodName = "getIdentityProvider";
    String idp = null;
    if (null != idTokenString) {
        IDToken idToken;
        try {
            idToken = new IDToken(idTokenString);
            final Map<String, ?> idTokenClaims = idToken.getTokenClaims();
            if (null != idTokenClaims) {
                // IDP claim is present only in case of guest scenerio and is empty for home tenants.
                // Few Apps consuming ADAL use this to differentiate between home vs guest accounts.
                idp = (String) idTokenClaims.get(AzureActiveDirectoryIdToken.IDENTITY_PROVIDER);
                Logger.verbosePII(TAG + ":" + methodName, "idp: " + idp);
                if (null == idp) {
                    Logger.info(TAG + ":" + methodName, "idp claim was null.");
                }
            } else {
                Logger.warn(TAG + ":" + methodName, "IDToken claims were null.");
            }
        } catch (ServiceException e) {
            Logger.warn(TAG + ":" + methodName, EXCEPTION_CONSTRUCTING_IDTOKEN + e.getMessage());
        }
    } else {
        Logger.warn(TAG + ":" + methodName, "IDToken was null.");
    }
    return idp;
}
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