Search in sources :

Example 1 with IAccountRecord

use of com.microsoft.identity.common.internal.dto.IAccountRecord in project microsoft-authentication-library-common-for-android by AzureAD.

the class SharedPreferencesAccountCredentialCache method removeAccount.

@Override
public boolean removeAccount(@NonNull final AccountRecord accountToRemove) {
    Logger.info(TAG, "Removing Account...");
    if (null == accountToRemove) {
        throw new IllegalArgumentException("Param [accountToRemove] cannot be null.");
    }
    final Map<String, AccountRecord> accounts = getAccountsWithKeys();
    boolean accountRemoved = false;
    for (final Map.Entry<String, AccountRecord> entry : accounts.entrySet()) {
        Logger.verbosePII(TAG, "Inspecting: [" + entry.getKey() + "]");
        final IAccountRecord currentAccount = entry.getValue();
        if (currentAccount.equals(accountToRemove)) {
            mSharedPreferencesFileManager.remove(entry.getKey());
            accountRemoved = true;
            break;
        }
    }
    Logger.info(TAG, "Account was removed? [" + accountRemoved + "]");
    return accountRemoved;
}
Also used : IAccountRecord(com.microsoft.identity.common.internal.dto.IAccountRecord) IAccountRecord(com.microsoft.identity.common.internal.dto.IAccountRecord) AccountRecord(com.microsoft.identity.common.internal.dto.AccountRecord) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with IAccountRecord

use of com.microsoft.identity.common.internal.dto.IAccountRecord in project microsoft-authentication-library-common-for-android by AzureAD.

the class AdalBrokerResultAdapter method bundleFromAuthenticationResult.

@Override
@NonNull
public Bundle bundleFromAuthenticationResult(@NonNull final ILocalAuthenticationResult authenticationResult, @Nullable final String negotiatedBrokerProtocolVersion) {
    Logger.verbose(TAG, "Constructing success bundle from Authentication Result.");
    final Bundle resultBundle = new Bundle();
    IAccountRecord accountRecord = authenticationResult.getAccountRecord();
    resultBundle.putString(AuthenticationConstants.Broker.ACCOUNT_LOGIN_HINT, accountRecord.getUsername());
    resultBundle.putString(AuthenticationConstants.Broker.ACCOUNT_USERINFO_USERID, accountRecord.getLocalAccountId());
    resultBundle.putString(AuthenticationConstants.Broker.ACCOUNT_USERINFO_USERID_DISPLAYABLE, accountRecord.getUsername());
    resultBundle.putString(AuthenticationConstants.Broker.ACCOUNT_USERINFO_GIVEN_NAME, accountRecord.getFirstName());
    resultBundle.putString(AuthenticationConstants.Broker.ACCOUNT_USERINFO_FAMILY_NAME, accountRecord.getFamilyName());
    resultBundle.putString(AuthenticationConstants.Broker.ACCOUNT_USERINFO_IDENTITY_PROVIDER, SchemaUtil.getIdentityProvider(authenticationResult.getIdToken()));
    resultBundle.putString(AuthenticationConstants.Broker.ACCOUNT_USERINFO_TENANTID, authenticationResult.getTenantId());
    resultBundle.putLong(AuthenticationConstants.Broker.ACCOUNT_EXPIREDATE, authenticationResult.getExpiresOn().getTime());
    resultBundle.putString(AuthenticationConstants.Broker.ACCOUNT_AUTHORITY, getAuthority(authenticationResult));
    resultBundle.putString(AuthenticationConstants.Broker.ACCOUNT_ACCESS_TOKEN, authenticationResult.getAccessToken());
    resultBundle.putString(AuthenticationConstants.Broker.ACCOUNT_IDTOKEN, authenticationResult.getIdToken());
    resultBundle.putString(SPE_RING, authenticationResult.getSpeRing());
    resultBundle.putString(RT_AGE, authenticationResult.getRefreshTokenAge());
    return resultBundle;
}
Also used : IAccountRecord(com.microsoft.identity.common.internal.dto.IAccountRecord) Bundle(android.os.Bundle) NonNull(androidx.annotation.NonNull)

Example 3 with IAccountRecord

use of com.microsoft.identity.common.internal.dto.IAccountRecord in project microsoft-authentication-library-common-for-android by AzureAD.

the class MsalBrokerResultAdapter method bundleFromAuthenticationResult.

@Override
@NonNull
public Bundle bundleFromAuthenticationResult(@NonNull final ILocalAuthenticationResult authenticationResult, @Nullable final String negotiatedBrokerProtocolVersion) {
    Logger.info(TAG, "Constructing result bundle from ILocalAuthenticationResult");
    final IAccountRecord accountRecord = authenticationResult.getAccountRecord();
    final AccessTokenRecord accessTokenRecord = authenticationResult.getAccessTokenRecord();
    final BrokerResult brokerResult = new BrokerResult.Builder().tenantProfileRecords(authenticationResult.getCacheRecordWithTenantProfileData()).accessToken(authenticationResult.getAccessToken()).idToken(authenticationResult.getIdToken()).refreshToken(authenticationResult.getRefreshToken()).homeAccountId(accountRecord.getHomeAccountId()).localAccountId(accountRecord.getLocalAccountId()).userName(accountRecord.getUsername()).tokenType(accessTokenRecord.getAccessTokenType()).clientId(accessTokenRecord.getClientId()).familyId(authenticationResult.getFamilyId()).scope(accessTokenRecord.getTarget()).clientInfo(accountRecord.getClientInfo()).authority(accessTokenRecord.getAuthority()).environment(accessTokenRecord.getEnvironment()).tenantId(authenticationResult.getTenantId()).expiresOn(Long.parseLong(accessTokenRecord.getExpiresOn())).extendedExpiresOn(Long.parseLong(accessTokenRecord.getExtendedExpiresOn())).cachedAt(Long.parseLong(accessTokenRecord.getCachedAt())).speRing(authenticationResult.getSpeRing()).refreshTokenAge(authenticationResult.getRefreshTokenAge()).success(true).servicedFromCache(authenticationResult.isServicedFromCache()).build();
    final Bundle resultBundle = bundleFromBrokerResult(brokerResult, negotiatedBrokerProtocolVersion);
    resultBundle.putBoolean(AuthenticationConstants.Broker.BROKER_REQUEST_V2_SUCCESS, true);
    return resultBundle;
}
Also used : IAccountRecord(com.microsoft.identity.common.internal.dto.IAccountRecord) BrokerResult(com.microsoft.identity.common.internal.broker.BrokerResult) Bundle(android.os.Bundle) AccessTokenRecord(com.microsoft.identity.common.internal.dto.AccessTokenRecord) NonNull(androidx.annotation.NonNull)

Aggregations

IAccountRecord (com.microsoft.identity.common.internal.dto.IAccountRecord)3 Bundle (android.os.Bundle)2 NonNull (androidx.annotation.NonNull)2 BrokerResult (com.microsoft.identity.common.internal.broker.BrokerResult)1 AccessTokenRecord (com.microsoft.identity.common.internal.dto.AccessTokenRecord)1 AccountRecord (com.microsoft.identity.common.internal.dto.AccountRecord)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1