Search in sources :

Example 1 with TokenErrorResponse

use of com.google.api.client.auth.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;
}
Also used : CliTelemInfo(com.microsoft.identity.common.internal.telemetry.CliTelemInfo) MicrosoftTokenErrorResponse(com.microsoft.identity.common.internal.providers.microsoft.MicrosoftTokenErrorResponse) TokenErrorResponse(com.microsoft.identity.common.internal.providers.oauth2.TokenErrorResponse) MicrosoftTokenErrorResponse(com.microsoft.identity.common.internal.providers.microsoft.MicrosoftTokenErrorResponse) TokenResult(com.microsoft.identity.common.internal.providers.oauth2.TokenResult) List(java.util.List) NonNull(androidx.annotation.NonNull)

Example 2 with TokenErrorResponse

use of com.google.api.client.auth.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()));
}
Also used : TokenErrorResponse(com.google.api.client.auth.oauth2.TokenErrorResponse) DefaultHttpResponseExceptionMappingService(ch.cyberduck.core.http.DefaultHttpResponseExceptionMappingService) HttpResponseException(org.apache.http.client.HttpResponseException)

Example 3 with TokenErrorResponse

use of com.google.api.client.auth.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;
}
Also used : MicrosoftTokenErrorResponse(com.microsoft.identity.common.internal.providers.microsoft.MicrosoftTokenErrorResponse) TokenErrorResponse(com.microsoft.identity.common.internal.providers.oauth2.TokenErrorResponse) MicrosoftTokenErrorResponse(com.microsoft.identity.common.internal.providers.microsoft.MicrosoftTokenErrorResponse) TokenResponse(com.microsoft.identity.common.internal.providers.oauth2.TokenResponse) TokenResult(com.microsoft.identity.common.internal.providers.oauth2.TokenResult)

Example 4 with TokenErrorResponse

use of com.google.api.client.auth.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() + "]");
}
Also used : TokenErrorResponse(com.microsoft.identity.common.internal.providers.oauth2.TokenErrorResponse)

Aggregations

TokenErrorResponse (com.microsoft.identity.common.internal.providers.oauth2.TokenErrorResponse)3 MicrosoftTokenErrorResponse (com.microsoft.identity.common.internal.providers.microsoft.MicrosoftTokenErrorResponse)2 TokenResult (com.microsoft.identity.common.internal.providers.oauth2.TokenResult)2 NonNull (androidx.annotation.NonNull)1 DefaultHttpResponseExceptionMappingService (ch.cyberduck.core.http.DefaultHttpResponseExceptionMappingService)1 TokenErrorResponse (com.google.api.client.auth.oauth2.TokenErrorResponse)1 TokenResponse (com.microsoft.identity.common.internal.providers.oauth2.TokenResponse)1 CliTelemInfo (com.microsoft.identity.common.internal.telemetry.CliTelemInfo)1 List (java.util.List)1 HttpResponseException (org.apache.http.client.HttpResponseException)1