use of com.microsoft.identity.common.internal.dto.RefreshTokenRecord 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.RefreshTokenRecord in project microsoft-authentication-library-common-for-android by AzureAD.
the class MsalOAuth2TokenCacheTest method testGetFamilyRefreshTokenForHomeAccountIdNullCase.
@Test
public void testGetFamilyRefreshTokenForHomeAccountIdNullCase() {
final RefreshTokenRecord refreshTokenRecord = mOauth2TokenCache.getFamilyRefreshTokenForHomeAccountId(HOME_ACCOUNT_ID);
assertNull(refreshTokenRecord);
}
use of com.microsoft.identity.common.internal.dto.RefreshTokenRecord in project microsoft-authentication-library-common-for-android by AzureAD.
the class MsalOAuth2TokenCacheTest method testFrtFallback.
@Test
public void testFrtFallback() throws ClientException {
// This test verifies changes in common/#893
// We will fallback on an FRT in the local cache for the current user if one is avail
final List<ICacheRecord> result = loadTestBundleIntoCacheWithAggregation(defaultTestBundleV2);
assertEquals(1, result.size());
final ICacheRecord entry = result.get(0);
assertNotNull(entry.getAccount());
assertNotNull(entry.getIdToken());
assertNotNull(entry.getAccessToken());
assertNotNull(entry.getRefreshToken());
// delete the existing RT and insert our FRT
accountCredentialCache.removeCredential(entry.getRefreshToken());
// Modify the existing RT to change the client_id and set a FoCI affiliation
final String fociRtClientId = UUID.randomUUID().toString();
final RefreshTokenRecord modifiedRT = entry.getRefreshToken();
modifiedRT.setFamilyId("1");
modifiedRT.setClientId(fociRtClientId);
accountCredentialCache.saveCredential(modifiedRT);
final ICacheRecord secondaryLoad = mOauth2TokenCache.load(entry.getAccessToken().getClientId(), TARGET, entry.getAccount(), BEARER_AUTHENTICATION_SCHEME);
assertNotNull(secondaryLoad.getRefreshToken());
assertEquals(fociRtClientId, secondaryLoad.getRefreshToken().getClientId());
}
use of com.microsoft.identity.common.internal.dto.RefreshTokenRecord in project microsoft-authentication-library-common-for-android by AzureAD.
the class MicrosoftStsAccountCredentialAdapterTest method createRefreshToken.
@Test
public void createRefreshToken() {
final RefreshTokenRecord refreshToken = mAccountCredentialAdapter.createRefreshToken(mockStrategy, mockRequest, mockResponse);
assertNotNull(refreshToken);
assertEquals(MOCK_SCOPE, refreshToken.getTarget());
assertNotNull(refreshToken.getCachedAt());
assertEquals(MOCK_FAMILY_ID, refreshToken.getFamilyId());
}
use of com.microsoft.identity.common.internal.dto.RefreshTokenRecord in project microsoft-authentication-library-common-for-android by AzureAD.
the class BaseController method getAccountWithFRTIfAvailable.
@Nullable
private AccountRecord getAccountWithFRTIfAvailable(@NonNull final SilentTokenCommandParameters parameters, @SuppressWarnings(WarningType.rawtype_warning) @NonNull final MsalOAuth2TokenCache msalOAuth2TokenCache) {
final String homeAccountId = parameters.getAccount().getHomeAccountId();
final String clientId = parameters.getClientId();
// check for FOCI tokens for the homeAccountId
final RefreshTokenRecord refreshTokenRecord = msalOAuth2TokenCache.getFamilyRefreshTokenForHomeAccountId(homeAccountId);
if (refreshTokenRecord != null) {
try {
// foci token is available, make a request to service to see if the client id is FOCI and save the tokens
TokenCacheItemMigrationAdapter.tryFociTokenWithGivenClientId(parameters.getOAuth2TokenCache(), clientId, parameters.getRedirectUri(), refreshTokenRecord, parameters.getAccount());
// Try to look for account again in the cache
return parameters.getOAuth2TokenCache().getAccountByLocalAccountId(null, clientId, parameters.getAccount().getLocalAccountId());
} catch (IOException | ClientException e) {
Logger.warn(TAG, "Error while attempting to validate client: " + clientId + " is part of family " + e.getMessage());
}
} else {
Logger.info(TAG, "No Foci tokens found for homeAccountId " + homeAccountId);
}
return null;
}
Aggregations