use of com.microsoft.identity.common.internal.dto.IdTokenRecord in project microsoft-authentication-library-common-for-android by AzureAD.
the class MsalOAuth2TokenCacheTest method testGetFamilyRefreshTokenForHomeAccountIdValidCase.
@Test
public void testGetFamilyRefreshTokenForHomeAccountIdValidCase() {
// Save an Account into the cache
final AccountRecord account = new AccountRecord();
account.setHomeAccountId(HOME_ACCOUNT_ID);
account.setEnvironment(ENVIRONMENT);
account.setRealm(REALM);
account.setLocalAccountId(LOCAL_ACCOUNT_ID);
account.setUsername(USERNAME);
account.setAuthorityType(AUTHORITY_TYPE);
accountCredentialCache.saveAccount(account);
// Save an AccessToken into the cache
final AccessTokenRecord accessToken = new AccessTokenRecord();
accessToken.setCredentialType(AccessToken.name());
accessToken.setHomeAccountId(HOME_ACCOUNT_ID);
accessToken.setRealm("Foo");
accessToken.setEnvironment(ENVIRONMENT);
accessToken.setClientId(CLIENT_ID);
accessToken.setTarget(TARGET);
accessToken.setCachedAt(CACHED_AT);
accessToken.setExpiresOn(EXPIRES_ON);
accessToken.setSecret(SECRET);
accountCredentialCache.saveCredential(accessToken);
// Save a Family RefreshToken into the cache
final RefreshTokenRecord refreshToken = new RefreshTokenRecord();
refreshToken.setCredentialType(RefreshToken.name());
refreshToken.setEnvironment(ENVIRONMENT);
refreshToken.setHomeAccountId(HOME_ACCOUNT_ID);
refreshToken.setClientId(CLIENT_ID);
refreshToken.setFamilyId("1");
refreshToken.setSecret(SECRET);
refreshToken.setTarget(TARGET);
accountCredentialCache.saveCredential(refreshToken);
final IdTokenRecord id = new IdTokenRecord();
id.setHomeAccountId(HOME_ACCOUNT_ID);
id.setEnvironment(ENVIRONMENT);
id.setRealm(REALM2);
id.setCredentialType(IdToken.name());
id.setClientId(CLIENT_ID);
id.setSecret(MOCK_ID_TOKEN_WITH_CLAIMS);
id.setAuthority("https://sts.windows.net/0287f963-2d72-4363-9e3a-5705c5b0f031/");
accountCredentialCache.saveCredential(id);
final RefreshTokenRecord refreshTokenRecord = mOauth2TokenCache.getFamilyRefreshTokenForHomeAccountId(HOME_ACCOUNT_ID);
assertNotNull(refreshTokenRecord);
assertEquals(refreshTokenRecord.getSecret(), SECRET);
}
use of com.microsoft.identity.common.internal.dto.IdTokenRecord 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.IdTokenRecord 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));
}
use of com.microsoft.identity.common.internal.dto.IdTokenRecord in project microsoft-authentication-library-common-for-android by AzureAD.
the class SharedPreferencesAccountCredentialCacheTest method malformedJsonCacheValueForIdToken.
@Test
public void malformedJsonCacheValueForIdToken() {
final IdTokenRecord idToken = new IdTokenRecord();
idToken.setHomeAccountId(HOME_ACCOUNT_ID);
idToken.setEnvironment(ENVIRONMENT);
idToken.setCredentialType(CredentialType.IdToken.name());
idToken.setClientId(CLIENT_ID);
// Generate a cache key
final String cacheKey = mDelegate.generateCacheKey(idToken);
mSharedPreferencesFileManager.putString(cacheKey, "{\"thing\" \"not an idToken\"}");
final IdTokenRecord restoredIdToken = (IdTokenRecord) mSharedPreferencesAccountCredentialCache.getCredential(cacheKey);
assertNull(restoredIdToken);
assertNotNull(mSharedPreferencesFileManager.getString(cacheKey));
}
use of com.microsoft.identity.common.internal.dto.IdTokenRecord in project microsoft-authentication-library-common-for-android by AzureAD.
the class SharedPreferencesAccountCredentialCacheTest method testIdTokenMerge.
@Test
public void testIdTokenMerge() {
final IdTokenRecord idTokenFirst = new IdTokenRecord();
idTokenFirst.setCredentialType(CredentialType.IdToken.name());
idTokenFirst.setHomeAccountId(HOME_ACCOUNT_ID);
idTokenFirst.setRealm(REALM);
idTokenFirst.setEnvironment(ENVIRONMENT);
idTokenFirst.setClientId(CLIENT_ID);
idTokenFirst.setCachedAt(CACHED_AT);
idTokenFirst.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);
idTokenFirst.setAdditionalFields(additionalFields);
// Save the Credential
mSharedPreferencesAccountCredentialCache.saveCredential(idTokenFirst);
final IdTokenRecord idTokenSecond = new IdTokenRecord();
idTokenSecond.setCredentialType(CredentialType.IdToken.name());
idTokenSecond.setHomeAccountId(HOME_ACCOUNT_ID);
idTokenSecond.setRealm(REALM);
idTokenSecond.setEnvironment(ENVIRONMENT);
idTokenSecond.setClientId(CLIENT_ID);
idTokenSecond.setCachedAt(CACHED_AT);
idTokenSecond.setSecret(SECRET);
// Create and set some additional field data...
final String additionalKey2 = "extra-prop-2";
final String additionalValue2 = "extra-value-2";
final JsonElement additionalValueElement2 = new JsonPrimitive(additionalValue2);
final Map<String, JsonElement> additionalFields2 = new HashMap<>();
additionalFields2.put(additionalKey2, additionalValueElement2);
idTokenSecond.setAdditionalFields(additionalFields2);
// Save the Credential
mSharedPreferencesAccountCredentialCache.saveCredential(idTokenSecond);
// Synthesize a cache key for it
final String credentialCacheKey = mDelegate.generateCacheKey(idTokenFirst);
// Resurrect the Credential
final Credential restoredIdToken = mSharedPreferencesAccountCredentialCache.getCredential(credentialCacheKey);
assertTrue(idTokenFirst.equals(restoredIdToken));
assertEquals(additionalValue, restoredIdToken.getAdditionalFields().get(additionalKey).getAsString());
assertEquals(additionalValue2, restoredIdToken.getAdditionalFields().get(additionalKey2).getAsString());
}
Aggregations