use of com.microsoft.identity.common.internal.providers.microsoft.microsoftsts.MicrosoftStsAccount in project microsoft-authentication-library-common-for-android by AzureAD.
the class BrokerMsalController method saveMsaAccountToCache.
/**
* Checks if the account returns is a MSA Account and sets single on state in cache
*/
private void saveMsaAccountToCache(@NonNull final Bundle resultBundle, @SuppressWarnings(WarningType.rawtype_warning) @NonNull final MsalOAuth2TokenCache msalOAuth2TokenCache) throws BaseException {
final String methodName = ":saveMsaAccountToCache";
final BrokerResult brokerResult = new MsalBrokerResultAdapter().brokerResultFromBundle(resultBundle);
if (resultBundle.getBoolean(AuthenticationConstants.Broker.BROKER_REQUEST_V2_SUCCESS) && AzureActiveDirectoryAudience.MSA_MEGA_TENANT_ID.equalsIgnoreCase(brokerResult.getTenantId())) {
Logger.info(TAG + methodName, "Result returned for MSA Account, saving to cache");
if (StringUtil.isEmpty(brokerResult.getClientInfo())) {
Logger.error(TAG + methodName, "ClientInfo is empty.", null);
throw new ClientException(ErrorStrings.UNKNOWN_ERROR, "ClientInfo is empty.");
}
try {
final ClientInfo clientInfo = new ClientInfo(brokerResult.getClientInfo());
final MicrosoftStsAccount microsoftStsAccount = new MicrosoftStsAccount(new IDToken(brokerResult.getIdToken()), clientInfo);
microsoftStsAccount.setEnvironment(brokerResult.getEnvironment());
final MicrosoftRefreshToken microsoftRefreshToken = new MicrosoftRefreshToken(brokerResult.getRefreshToken(), clientInfo, brokerResult.getScope(), brokerResult.getClientId(), brokerResult.getEnvironment(), brokerResult.getFamilyId());
msalOAuth2TokenCacheSetSingleSignOnState(msalOAuth2TokenCache, microsoftStsAccount, microsoftRefreshToken);
} catch (ServiceException e) {
Logger.errorPII(TAG + methodName, "Exception while creating Idtoken or ClientInfo," + " cannot save MSA account tokens", e);
throw new ClientException(ErrorStrings.INVALID_JWT, e.getMessage(), e);
}
}
}
Aggregations