use of com.microsoft.identity.common.internal.dto.Credential in project microsoft-authentication-library-common-for-android by AzureAD.
the class SharedPreferencesAccountCredentialCacheTest method persistAndRestoreExtraClaimsIdToken.
@Test
public void persistAndRestoreExtraClaimsIdToken() {
final IdTokenRecord idToken = new IdTokenRecord();
idToken.setHomeAccountId(HOME_ACCOUNT_ID);
idToken.setEnvironment(ENVIRONMENT);
idToken.setRealm(REALM);
idToken.setCredentialType(CredentialType.IdToken.name());
idToken.setClientId(CLIENT_ID);
idToken.setSecret(SECRET);
// Create and set some additional field data...
final String additionalKey = "extra-prop-1";
final String additionalValue = "extra-value-1";
final JsonElement additionalValueElement = new JsonPrimitive(additionalValue);
final Map<String, JsonElement> additionalFields = new HashMap<>();
additionalFields.put(additionalKey, additionalValueElement);
idToken.setAdditionalFields(additionalFields);
// Save the Credential
mSharedPreferencesAccountCredentialCache.saveCredential(idToken);
// Synthesize a cache key for it
final String credentialCacheKey = mDelegate.generateCacheKey(idToken);
// Resurrect the Credential
final Credential restoredIdToken = mSharedPreferencesAccountCredentialCache.getCredential(credentialCacheKey);
assertTrue(idToken.equals(restoredIdToken));
assertEquals(additionalValue, restoredIdToken.getAdditionalFields().get(additionalKey).getAsString());
}
use of com.microsoft.identity.common.internal.dto.Credential in project microsoft-authentication-library-common-for-android by AzureAD.
the class SharedPreferencesAccountCredentialCacheTest method getCredentialsPRTAnotherClientId.
@Test
public void getCredentialsPRTAnotherClientId() {
final PrimaryRefreshTokenRecord primaryRefreshToken = new PrimaryRefreshTokenRecord();
primaryRefreshToken.setHomeAccountId(HOME_ACCOUNT_ID);
primaryRefreshToken.setEnvironment(ENVIRONMENT);
primaryRefreshToken.setCredentialType(CredentialType.PrimaryRefreshToken.name().toLowerCase(Locale.US));
primaryRefreshToken.setClientId(CLIENT_ID);
primaryRefreshToken.setSessionKey(SESSION_KEY);
mSharedPreferencesAccountCredentialCache.saveCredential(primaryRefreshToken);
List<Credential> credentials = mSharedPreferencesAccountCredentialCache.getCredentialsFilteredBy(HOME_ACCOUNT_ID, ENVIRONMENT, CredentialType.PrimaryRefreshToken, "another-client-id", null, null, null);
assertTrue(credentials.isEmpty());
}
use of com.microsoft.identity.common.internal.dto.Credential in project microsoft-authentication-library-common-for-android by AzureAD.
the class SharedPreferencesAccountCredentialCacheTest method getCredentialsWhenRequestedClaimsAreSpecified.
@Test
public void getCredentialsWhenRequestedClaimsAreSpecified() {
final RefreshTokenRecord refreshToken = new RefreshTokenRecord();
refreshToken.setSecret(SECRET);
refreshToken.setHomeAccountId(HOME_ACCOUNT_ID);
refreshToken.setEnvironment(ENVIRONMENT);
refreshToken.setCredentialType(CredentialType.RefreshToken.name());
refreshToken.setClientId(CLIENT_ID);
refreshToken.setTarget(TARGET);
final AccessTokenRecord accessToken = new AccessTokenRecord();
accessToken.setCachedAt(CACHED_AT);
accessToken.setExpiresOn(EXPIRES_ON);
accessToken.setSecret(SECRET);
accessToken.setHomeAccountId(HOME_ACCOUNT_ID);
accessToken.setRealm(REALM);
accessToken.setEnvironment(ENVIRONMENT);
accessToken.setCredentialType(CredentialType.AccessToken.name());
accessToken.setClientId(CLIENT_ID);
accessToken.setTarget(TARGET);
final AccessTokenRecord accessToken2 = new AccessTokenRecord();
accessToken2.setCachedAt(CACHED_AT);
accessToken2.setExpiresOn(EXPIRES_ON);
accessToken2.setSecret(SECRET);
accessToken2.setHomeAccountId(HOME_ACCOUNT_ID);
accessToken2.setRealm(REALM);
accessToken2.setEnvironment(ENVIRONMENT);
accessToken2.setCredentialType(CredentialType.AccessToken.name());
accessToken2.setClientId(CLIENT_ID);
accessToken2.setTarget(TARGET);
accessToken2.setRequestedClaims("{\"access_token\":{\"deviceid\":{\"essential\":true}}}");
// Save the Credentials
mSharedPreferencesAccountCredentialCache.saveCredential(refreshToken);
mSharedPreferencesAccountCredentialCache.saveCredential(accessToken);
mSharedPreferencesAccountCredentialCache.saveCredential(accessToken2);
List<Credential> credentials = mSharedPreferencesAccountCredentialCache.getCredentialsFilteredBy(HOME_ACCOUNT_ID, ENVIRONMENT, CredentialType.AccessToken, CLIENT_ID, REALM, null, BEARER_AUTHENTICATION_SCHEME.getName(), "{\"access_token\":{\"deviceid\":{\"essential\":true}}}");
assertEquals(1, credentials.size());
}
use of com.microsoft.identity.common.internal.dto.Credential in project microsoft-authentication-library-common-for-android by AzureAD.
the class SharedPreferencesAccountCredentialCacheTest method saveCredentialNoRealmNoTarget.
@Test
public void saveCredentialNoRealmNoTarget() {
final AccessTokenRecord accessToken = new AccessTokenRecord();
accessToken.setCachedAt(CACHED_AT);
accessToken.setExpiresOn(EXPIRES_ON);
accessToken.setSecret(SECRET);
accessToken.setHomeAccountId(HOME_ACCOUNT_ID);
accessToken.setEnvironment(ENVIRONMENT);
accessToken.setCredentialType(CredentialType.AccessToken.name());
accessToken.setClientId(CLIENT_ID);
// Save the Credential
mSharedPreferencesAccountCredentialCache.saveCredential(accessToken);
// Synthesize a cache key for it
final String credentialCacheKey = mDelegate.generateCacheKey(accessToken);
// Resurrect the Credential
final Credential restoredAccessToken = mSharedPreferencesAccountCredentialCache.getCredential(credentialCacheKey);
assertTrue(accessToken.equals(restoredAccessToken));
}
use of com.microsoft.identity.common.internal.dto.Credential in project microsoft-authentication-library-common-for-android by AzureAD.
the class SharedPreferencesAccountCredentialCacheTest method saveIdToken.
@Test
public void saveIdToken() {
final IdTokenRecord idToken = new IdTokenRecord();
idToken.setHomeAccountId(HOME_ACCOUNT_ID);
idToken.setEnvironment(ENVIRONMENT);
idToken.setRealm(REALM);
idToken.setCredentialType(CredentialType.IdToken.name());
idToken.setClientId(CLIENT_ID);
idToken.setSecret(SECRET);
// Save the Credential
mSharedPreferencesAccountCredentialCache.saveCredential(idToken);
// Synthesize a cache key for it
final String credentialCacheKey = mDelegate.generateCacheKey(idToken);
// Resurrect the Credential
final Credential restoredIdToken = mSharedPreferencesAccountCredentialCache.getCredential(credentialCacheKey);
assertEquals(idToken.getHomeAccountId(), restoredIdToken.getHomeAccountId());
assertEquals(idToken.getEnvironment(), restoredIdToken.getEnvironment());
assertEquals(idToken.getCredentialType(), restoredIdToken.getCredentialType());
assertEquals(idToken.getClientId(), restoredIdToken.getClientId());
assertTrue(idToken.equals(restoredIdToken));
}
Aggregations