com.google.api.client.auth.oauth2.TokenErrorResponse Java Examples
The following examples show how to use
com.google.api.client.auth.oauth2.TokenErrorResponse.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GoogleCredentialFactory.java From data-transfer-project with Apache License 2.0 | 6 votes |
/** Refreshes and updates the given credential */ public Credential refreshCredential(Credential credential) throws IOException, InvalidTokenException { try { TokenResponse tokenResponse = new RefreshTokenRequest( httpTransport, jsonFactory, new GenericUrl(credential.getTokenServerEncodedUrl()), credential.getRefreshToken()) .setClientAuthentication(credential.getClientAuthentication()) .setRequestInitializer(credential.getRequestInitializer()) .execute(); return credential.setFromTokenResponse(tokenResponse); } catch (TokenResponseException e) { TokenErrorResponse details = e.getDetails(); if (details != null && details.getError().equals("invalid_grant")) { throw new InvalidTokenException("Unable to refresh token.", e); } else { throw e; } } }
Example #2
Source File: OAuthExceptionMappingService.java From cyberduck with GNU General Public License v3.0 | 5 votes |
@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())); }
Example #3
Source File: LenientTokenResponseException.java From android-oauth-client with Apache License 2.0 | 5 votes |
/** * Returns a new instance of {@link LenientTokenResponseException}. * <p> * If there is a JSON error response, it is parsed using * {@link TokenErrorResponse}, which can be inspected using * {@link #getDetails()}. Otherwise, the full response content is read and * included in the exception message. * </p> * * @param jsonFactory JSON factory * @param readResponse an HTTP response that has already been read * @param responseContent the content String of the HTTP response * @return new instance of {@link TokenErrorResponse} */ public static LenientTokenResponseException from(JsonFactory jsonFactory, HttpResponse readResponse, String responseContent) { HttpResponseException.Builder builder = new HttpResponseException.Builder( readResponse.getStatusCode(), readResponse.getStatusMessage(), readResponse.getHeaders()); // details Preconditions.checkNotNull(jsonFactory); TokenErrorResponse details = null; String detailString = null; String contentType = readResponse.getContentType(); try { if (/* !response.isSuccessStatusCode() && */true && contentType != null && HttpMediaType.equalsIgnoreParameters(Json.MEDIA_TYPE, contentType)) { details = readResponse .getRequest() .getParser() .parseAndClose(new StringReader(responseContent), TokenErrorResponse.class); detailString = details.toPrettyString(); } else { detailString = responseContent; } } catch (IOException exception) { // it would be bad to throw an exception while throwing an exception exception.printStackTrace(); } // message StringBuilder message = HttpResponseException.computeMessageBuffer(readResponse); if (!com.google.api.client.util.Strings.isNullOrEmpty(detailString)) { message.append(StringUtils.LINE_SEPARATOR).append(detailString); builder.setContent(detailString); } builder.setMessage(message.toString()); return new LenientTokenResponseException(builder, details); }
Example #4
Source File: LenientTokenResponseException.java From android-oauth-client with Apache License 2.0 | 2 votes |
/** * @param builder builder * @param details token error response details or {@code null} if unable to * parse */ LenientTokenResponseException(Builder builder, TokenErrorResponse details) { super(builder); this.details = details; }
Example #5
Source File: LenientTokenResponseException.java From android-oauth-client with Apache License 2.0 | 2 votes |
/** * Returns the token error response details or {@code null} if unable to * parse. */ public final TokenErrorResponse getDetails() { return details; }