use of com.microsoft.identity.common.internal.net.HttpResponse in project microsoft-authentication-library-common-for-android by AzureAD.
the class MockServerResponse method getMockTokenFailureProtectionPolicyRequiredResponse.
public static HttpResponse getMockTokenFailureProtectionPolicyRequiredResponse() {
final MicrosoftTokenErrorResponse tokenErrorResponse = new MicrosoftTokenErrorResponse();
tokenErrorResponse.setError("unauthorized_client");
tokenErrorResponse.setErrorDescription("AADSTS53005: Application needs to enforce Intune protection policies");
tokenErrorResponse.setErrorCodes(new ArrayList<Long>(Arrays.asList(70000L)));
tokenErrorResponse.setTimeStamp("2019-10-23 21:05:16Z");
tokenErrorResponse.setTraceId("8497799a-e9f9-402f-a951-7060b5014600");
tokenErrorResponse.setCorrelationId("390d7507-c607-4f05-bb8a-51a2a7a6282b");
tokenErrorResponse.setErrorUri("https://login.microsoftonline.com/error?code=70000");
tokenErrorResponse.setSubError("protection_policy_required");
final String mockResponse = ObjectMapper.serializeObjectToJsonString(tokenErrorResponse);
final HttpResponse response = new HttpResponse(400, mockResponse, new HashMap<String, List<String>>());
return response;
}
use of com.microsoft.identity.common.internal.net.HttpResponse in project microsoft-authentication-library-common-for-android by AzureAD.
the class MockServerResponse method getMockTokenFailureServiceUnavailable.
public static HttpResponse getMockTokenFailureServiceUnavailable() {
final MicrosoftTokenErrorResponse tokenErrorResponse = new MicrosoftTokenErrorResponse();
tokenErrorResponse.setError("service_unavailable");
tokenErrorResponse.setErrorDescription("AADSTS70000: Service is unavailable");
tokenErrorResponse.setErrorCodes(new ArrayList<Long>(Arrays.asList(70000L)));
tokenErrorResponse.setTimeStamp("2019-10-23 21:05:16Z");
tokenErrorResponse.setTraceId("8497799a-e9f9-402f-a951-7060b5014600");
tokenErrorResponse.setCorrelationId("390d7507-c607-4f05-bb8a-51a2a7a6282b");
tokenErrorResponse.setErrorUri("https://login.microsoftonline.com/error?code=70000");
tokenErrorResponse.setSubError("bad_token");
final String mockResponse = ObjectMapper.serializeObjectToJsonString(tokenErrorResponse);
final HttpResponse response = new HttpResponse(503, mockResponse, new HashMap<String, List<String>>());
return response;
}
use of com.microsoft.identity.common.internal.net.HttpResponse in project microsoft-authentication-library-common-for-android by AzureAD.
the class MockServerResponse method getMockTokenSuccessResponse.
public static HttpResponse getMockTokenSuccessResponse(final String localAccountId, final String tenant, final String issuer, final String rawClientInfo, final String accessToken) {
final MicrosoftTokenResponse mockTokenResponse = new MicrosoftTokenResponse();
mockTokenResponse.setTokenType("Bearer");
mockTokenResponse.setScope("User.Read");
mockTokenResponse.setExpiresIn(defaultTokenExpiryInSec);
mockTokenResponse.setExtExpiresIn(defaultTokenExpiryInSec);
mockTokenResponse.setAccessToken(accessToken);
mockTokenResponse.setRefreshToken("6b80f5b5-d53c-4c46-992d-66c5dcd4cfb1");
mockTokenResponse.setIdToken(MockTokenCreator.createMockIdTokenWithObjectIdTenantIdAndIssuer(localAccountId, tenant, issuer));
mockTokenResponse.setClientInfo(rawClientInfo);
final String mockResponse = ObjectMapper.serializeObjectToJsonString(mockTokenResponse);
return new HttpResponse(200, mockResponse, new HashMap<>());
}
use of com.microsoft.identity.common.internal.net.HttpResponse in project microsoft-authentication-library-common-for-android by AzureAD.
the class OpenIdProviderConfigurationClient method loadOpenIdProviderConfiguration.
/**
* Get OpenID provider configuration.
*
* @return OpenIdProviderConfiguration
*/
public synchronized OpenIdProviderConfiguration loadOpenIdProviderConfiguration() throws ServiceException {
final String methodName = ":loadOpenIdProviderConfiguration";
try {
final URL configUrl = new URL(mIssuer + sWellKnownConfig);
// Check first for a cached copy...
final OpenIdProviderConfiguration cacheResult = sConfigCache.get(configUrl);
// If we found a result, return it...
if (null != cacheResult) {
Logger.info(TAG + methodName, "Using cached metadata result.");
return cacheResult;
}
Logger.verbose(TAG + methodName, "Config URL is valid.");
Logger.verbosePII(TAG + methodName, "Using request URL: " + configUrl);
final HttpResponse providerConfigResponse = httpClient.get(configUrl, new HashMap<String, String>());
final int statusCode = providerConfigResponse.getStatusCode();
if (HttpURLConnection.HTTP_OK != statusCode || TextUtils.isEmpty(providerConfigResponse.getBody())) {
throw new ServiceException(OPENID_PROVIDER_CONFIGURATION_FAILED_TO_LOAD, "OpenId Provider Configuration metadata failed to load with status: " + statusCode, null);
}
final OpenIdProviderConfiguration parsedConfig = parseMetadata(providerConfigResponse.getBody());
// Cache our config in memory for later
cacheConfiguration(configUrl, parsedConfig);
return parsedConfig;
} catch (IOException e) {
throw new ServiceException(OPENID_PROVIDER_CONFIGURATION_FAILED_TO_LOAD, "IOException while requesting metadata", e);
}
}
use of com.microsoft.identity.common.internal.net.HttpResponse in project microsoft-authentication-library-common-for-android by AzureAD.
the class OAuth2Strategy method performTokenRequest.
protected HttpResponse performTokenRequest(final GenericTokenRequest request) throws IOException, ClientException {
final String methodName = ":performTokenRequest";
Logger.verbose(TAG + methodName, "Performing token request...");
final String requestBody = getRequestBody(request);
final Map<String, String> headers = new TreeMap<>();
headers.put(CLIENT_REQUEST_ID, DiagnosticContext.getRequestContext().get(DiagnosticContext.CORRELATION_ID));
if (request instanceof MicrosoftTokenRequest && !TextUtils.isEmpty(((MicrosoftTokenRequest) request).getBrokerVersion())) {
headers.put(Device.PlatformIdParameters.BROKER_VERSION, ((MicrosoftTokenRequest) request).getBrokerVersion());
}
headers.putAll(Device.getPlatformIdParameters());
headers.put(AuthenticationConstants.SdkPlatformFields.PRODUCT, DiagnosticContext.getRequestContext().get(AuthenticationConstants.SdkPlatformFields.PRODUCT));
headers.put(AuthenticationConstants.SdkPlatformFields.VERSION, Device.getProductVersion());
headers.putAll(EstsTelemetry.getInstance().getTelemetryHeaders());
headers.put(HttpConstants.HeaderField.CONTENT_TYPE, TOKEN_REQUEST_CONTENT_TYPE);
if (request instanceof MicrosoftTokenRequest) {
headers.put(AuthenticationConstants.AAD.APP_PACKAGE_NAME, ((MicrosoftTokenRequest) request).getClientAppName());
headers.put(AuthenticationConstants.AAD.APP_VERSION, ((MicrosoftTokenRequest) request).getClientAppVersion());
}
final URL requestUrl = new URL(getTokenEndpoint());
final HttpResponse response = httpClient.post(requestUrl, headers, requestBody.getBytes(ObjectMapper.ENCODING_SCHEME));
// Record the clock skew between *this device* and EVO...
if (null != response.getDate()) {
recordClockSkew(response.getDate().getTime());
}
return response;
}
Aggregations