use of com.microsoft.identity.common.internal.providers.oauth2.TokenErrorResponse in project microsoft-authentication-library-common-for-android by AzureAD.
the class MicrosoftStsOAuth2Strategy method getTokenResultFromHttpResponse.
@Override
@NonNull
protected TokenResult getTokenResultFromHttpResponse(@NonNull final HttpResponse response) throws ClientException {
final String methodName = ":getTokenResultFromHttpResponse";
Logger.verbose(TAG + methodName, "Getting TokenResult from HttpResponse...");
MicrosoftStsTokenResponse tokenResponse = null;
TokenErrorResponse tokenErrorResponse = null;
if (response.getStatusCode() >= HttpURLConnection.HTTP_BAD_REQUEST) {
// An error occurred
tokenErrorResponse = ObjectMapper.deserializeJsonStringToObject(response.getBody(), MicrosoftTokenErrorResponse.class);
tokenErrorResponse.setStatusCode(response.getStatusCode());
if (null != response.getHeaders()) {
tokenErrorResponse.setResponseHeadersJson(HeaderSerializationUtil.toJson(response.getHeaders()));
}
tokenErrorResponse.setResponseBody(response.getBody());
} else {
tokenResponse = ObjectMapper.deserializeJsonStringToObject(getBodyFromSuccessfulResponse(response.getBody()), MicrosoftStsTokenResponse.class);
}
final TokenResult result = new TokenResult(tokenResponse, tokenErrorResponse);
logResult(TAG, result);
if (null != response.getHeaders()) {
final Map<String, List<String>> responseHeaders = response.getHeaders();
final List<String> cliTelemValues;
if (null != (cliTelemValues = responseHeaders.get(X_MS_CLITELEM)) && !cliTelemValues.isEmpty()) {
// Element should only contain 1 value...
final String cliTelemHeader = cliTelemValues.get(0);
final CliTelemInfo cliTelemInfo = CliTelemInfo.fromXMsCliTelemHeader(cliTelemHeader);
// Parse and set the result...
result.setCliTelemInfo(cliTelemInfo);
if (null != tokenResponse && null != cliTelemInfo) {
tokenResponse.setSpeRing(cliTelemInfo.getSpeRing());
tokenResponse.setRefreshTokenAge(cliTelemInfo.getRefreshTokenAge());
tokenResponse.setCliTelemErrorCode(cliTelemInfo.getServerErrorCode());
tokenResponse.setCliTelemSubErrorCode(cliTelemInfo.getServerSubErrorCode());
}
}
}
return result;
}
use of com.microsoft.identity.common.internal.providers.oauth2.TokenErrorResponse in project cyberduck by iterate-ch.
the class OAuthExceptionMappingService method map.
@Override
public BackgroundException map(final TokenResponseException failure) {
final StringBuilder buffer = new StringBuilder();
final TokenErrorResponse details = failure.getDetails();
if (null != details) {
this.append(buffer, details.getErrorDescription());
}
return new DefaultHttpResponseExceptionMappingService().map(new HttpResponseException(failure.getStatusCode(), buffer.toString()));
}
use of com.microsoft.identity.common.internal.providers.oauth2.TokenErrorResponse in project microsoft-authentication-library-common-for-android by AzureAD.
the class AzureActiveDirectoryOAuth2Strategy method getTokenResultFromHttpResponse.
@Override
protected TokenResult getTokenResultFromHttpResponse(final HttpResponse response) {
final String methodName = "getTokenResultFromHttpResponse";
TokenResponse tokenResponse = null;
TokenErrorResponse tokenErrorResponse = null;
if (response.getStatusCode() >= HttpURLConnection.HTTP_BAD_REQUEST) {
// An error occurred
Logger.warn(TAG + ":" + methodName, "Status code was: " + response.getStatusCode());
tokenErrorResponse = ObjectMapper.deserializeJsonStringToObject(response.getBody(), MicrosoftTokenErrorResponse.class);
} else {
tokenResponse = ObjectMapper.deserializeJsonStringToObject(response.getBody(), AzureActiveDirectoryTokenResponse.class);
}
final TokenResult result = new TokenResult(tokenResponse, tokenErrorResponse);
return result;
}
use of com.microsoft.identity.common.internal.providers.oauth2.TokenErrorResponse in project microsoft-authentication-library-common-for-android by AzureAD.
the class TokenCacheItemMigrationAdapter method logTokenResultError.
/**
* Logs errors from the {@link TokenResult}.
*
* @param correlationId The correlation id of the request.
* @param tokenResult The TokenResult whose errors should be logged.
*/
public static void logTokenResultError(@NonNull final UUID correlationId, @NonNull final TokenResult tokenResult) {
final TokenErrorResponse tokenErrorResponse = tokenResult.getErrorResponse();
Logger.warn(TAG, correlationId.toString(), "Status code: [" + tokenErrorResponse.getStatusCode() + "]");
Logger.warn(TAG, correlationId.toString(), "Error description: [" + tokenErrorResponse.getErrorDescription() + "]");
}
Aggregations