use of com.microsoft.identity.common.exception.ClientException in project microsoft-authentication-library-common-for-android by AzureAD.
the class BrokerActivity method returnsExceptionOnActivityUnexpectedlyKilled.
private void returnsExceptionOnActivityUnexpectedlyKilled() {
final IBrokerResultAdapter resultAdapter = BrokerResultAdapterFactory.getBrokerResultAdapter(SdkType.MSAL);
final Bundle resultBundle = resultAdapter.bundleFromBaseException(new ClientException(ErrorStrings.BROKER_REQUEST_CANCELLED, "The activity is killed unexpectedly."), null);
final Intent data = new Intent();
data.putExtras(resultBundle);
data.setAction(RETURN_INTERACTIVE_REQUEST_RESULT);
data.putExtra(REQUEST_CODE, AuthenticationConstants.UIRequest.BROWSER_FLOW);
data.putExtra(RESULT_CODE, AuthenticationConstants.UIResponse.BROWSER_CODE_CANCEL);
LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(data);
}
use of com.microsoft.identity.common.exception.ClientException in project microsoft-authentication-library-common-for-android by AzureAD.
the class AuthorizationStrategyFactory method getAuthorizationStrategy.
public GenericAuthorizationStrategy getAuthorizationStrategy(@NonNull final InteractiveTokenCommandParameters parameters) {
final Context context = parameters.getAndroidApplicationContext();
// Valid if available browser installed. Will fallback to embedded webView if no browser available.
final AuthorizationAgent validatedAuthorizationAgent = validAuthorizationAgent(parameters.getAuthorizationAgent(), context);
boolean isBrokerRequest = (parameters instanceof BrokerInteractiveTokenCommandParameters);
if (validatedAuthorizationAgent == AuthorizationAgent.WEBVIEW) {
Logger.info(TAG, "Use webView for authorization.");
return getGenericAuthorizationStrategy(parameters, context);
} else if (validatedAuthorizationAgent == AuthorizationAgent.DEFAULT) {
// Fall back to webview if no browser found.
try {
BrowserSelector.select(context, parameters.getBrowserSafeList());
} catch (final ClientException exception) {
Logger.info(TAG, "No supported browser available found. Fallback to the webView authorization agent.");
if (ErrorStrings.NO_AVAILABLE_BROWSER_FOUND.equalsIgnoreCase(exception.getErrorCode())) {
return getGenericAuthorizationStrategy(parameters, context);
}
}
Logger.info(TAG, "Use browser for authorization.");
return getBrowserAuthorizationStrategy(context, parameters.getActivity(), parameters.getFragment(), isBrokerRequest, parameters.getBrowserSafeList());
} else {
Logger.info(TAG, "Use browser for authorization.");
return getBrowserAuthorizationStrategy(context, parameters.getActivity(), parameters.getFragment(), isBrokerRequest, parameters.getBrowserSafeList());
}
}
use of com.microsoft.identity.common.exception.ClientException in project microsoft-authentication-library-common-for-android by AzureAD.
the class PKeyAuthChallengeHandler method getChallengeHeader.
public static Map<String, String> getChallengeHeader(final PKeyAuthChallenge pKeyAuthChallenge) throws ClientException {
String authorizationHeaderValue = String.format("%s Context=\"%s\",Version=\"%s\"", AuthenticationConstants.Broker.CHALLENGE_RESPONSE_TYPE, pKeyAuthChallenge.getContext(), pKeyAuthChallenge.getVersion());
// If not device cert exists, alias or private key will not exist on the device
// Suppressing unchecked warnings due to the generic type not provided in the object returned from method getDeviceCertificateProxy
@SuppressWarnings(WarningType.unchecked_warning) Class<IDeviceCertificate> certClazz = (Class<IDeviceCertificate>) AuthenticationSettings.INSTANCE.getDeviceCertificateProxy();
if (certClazz != null) {
IDeviceCertificate deviceCertProxy = getWPJAPIInstance(certClazz);
if (deviceCertProxy.isValidIssuer(pKeyAuthChallenge.getCertAuthorities()) || StringUtil.equalsIgnoreCase(deviceCertProxy.getThumbPrint(), pKeyAuthChallenge.getThumbprint())) {
RSAPrivateKey privateKey = deviceCertProxy.getRSAPrivateKey();
if (privateKey == null) {
throw new ClientException(ErrorStrings.KEY_CHAIN_PRIVATE_KEY_EXCEPTION);
}
final String jwt = (new JWSBuilder()).generateSignedJWT(pKeyAuthChallenge.getNonce(), pKeyAuthChallenge.getSubmitUrl(), privateKey, deviceCertProxy.getRSAPublicKey(), deviceCertProxy.getCertificate());
authorizationHeaderValue = String.format("%s AuthToken=\"%s\",Context=\"%s\",Version=\"%s\"", AuthenticationConstants.Broker.CHALLENGE_RESPONSE_TYPE, jwt, pKeyAuthChallenge.getContext(), pKeyAuthChallenge.getVersion());
Logger.info(TAG, "Receive challenge response. ");
}
}
final Map<String, String> headers = new HashMap<>();
headers.put(AuthenticationConstants.Broker.CHALLENGE_RESPONSE_HEADER, authorizationHeaderValue);
return headers;
}
use of com.microsoft.identity.common.exception.ClientException in project microsoft-authentication-library-common-for-android by AzureAD.
the class ConfidentialClientHelper method requestAccessTokenForAutomation.
/**
* Yep. Hardcoding this method to retrieve access token for MSIDLABS
*/
private String requestAccessTokenForAutomation() throws CertificateException, UnrecoverableKeyException, NoSuchAlgorithmException, KeyStoreException, NoSuchProviderException, IOException {
String accessToken = null;
final TokenRequest tokenRequest = this.createTokenRequest();
tokenRequest.setGrantType(CLIENT_CREDENTIALS);
final AccountsInOneOrganization aadAudience = new AccountsInOneOrganization(TENANT_ID);
final AzureActiveDirectoryAuthority authority = new AzureActiveDirectoryAuthority(aadAudience);
try {
final OAuth2StrategyParameters strategyParameters = new OAuth2StrategyParameters();
OAuth2Strategy<AccessToken, BaseAccount, AuthorizationRequest, AuthorizationRequest.Builder, AuthorizationStrategy, OAuth2Configuration, OAuth2StrategyParameters, AuthorizationResponse, RefreshToken, TokenRequest, TokenResponse, TokenResult, AuthorizationResult> strategy = authority.createOAuth2Strategy(strategyParameters);
TokenResult tokenResult = strategy.requestToken(tokenRequest);
if (tokenResult.getSuccess()) {
accessToken = tokenResult.getTokenResponse().getAccessToken();
} else {
throw new RuntimeException(tokenResult.getErrorResponse().getErrorDescription());
}
} catch (final ClientException e) {
e.printStackTrace();
}
return accessToken;
}
Aggregations