@Test(expectedExceptions = OAuthException.class) public void refreshTokenThrowsOAuthExceptionOnErrorStatus() throws JsonProcessingException, OAuthException { ObjectWriter writer = mapper.writerFor(BearerTokenResponse.class); Response mockResponse = new Response( IOUtils.toInputStream(writer.writeValueAsString(new BearerTokenResponse()), StandardCharsets.UTF_8), 500, intuit_tid); mockedHttpRequestClient.setMockResponse(mockResponse); oAuth2PlatformClient.retrieveBearerTokens(AUTH_CODE, REDIRECT_URI); }
public BearerTokenResponse retrieveBearerTokens(String authCode, String redirectURI) throws OAuthException { logger.debug("Enter OAuth2PlatformClient::retrieveBearerTokens"); try { HttpRequestClient client = new HttpRequestClient(oauth2Config.getProxyConfig()); Request request = new Request.RequestBuilder(MethodType.POST, oauth2Config.getIntuitBearerTokenEndpoint()) .requiresAuthentication(true) .authString(getAuthHeader()) .postParams(getUrlParameters(null, authCode, redirectURI)) .build(); Response response = client.makeRequest(request); logger.debug("Response Code : "+ response.getStatusCode()); logger.debug("intuit_tid : "+ response.getIntuit_tid()); if (response.getStatusCode() != 200) { logger.debug("failed getting access token"); logger.debug("Response content : "+ response.getContent()); throw new OAuthException("Failed getting access token", response.getStatusCode() + "", response.getIntuit_tid(), response); } ObjectReader reader = mapper.readerFor(BearerTokenResponse.class); BearerTokenResponse bearerTokenResponse = reader.readValue(response.getContent()); bearerTokenResponse.setIntuit_tid(response.getIntuit_tid()); return bearerTokenResponse; } catch (OAuthException ex) { logger.error("OAuthException while retrieving bearer tokens: " + ex.getResponseContent()); throw new OAuthException("Failed getting access token", ex.getStatusCode() + "", ex.getIntuit_tid(), ex.getResponse()); } catch (Exception ex) { logger.error("Exception while retrieving bearer tokens", ex); throw new OAuthException(ex.getMessage(), ex); } }
OAuth2PlatformClient { public BearerTokenResponse retrieveBearerTokens(String authCode, String redirectURI) throws OAuthException { logger.debug("Enter OAuth2PlatformClient::retrieveBearerTokens"); try { HttpRequestClient client = new HttpRequestClient(oauth2Config.getProxyConfig()); Request request = new Request.RequestBuilder(MethodType.POST, oauth2Config.getIntuitBearerTokenEndpoint()) .requiresAuthentication(true) .authString(getAuthHeader()) .postParams(getUrlParameters(null, authCode, redirectURI)) .build(); Response response = client.makeRequest(request); logger.debug("Response Code : "+ response.getStatusCode()); logger.debug("intuit_tid : "+ response.getIntuit_tid()); if (response.getStatusCode() != 200) { logger.debug("failed getting access token"); logger.debug("Response content : "+ response.getContent()); throw new OAuthException("Failed getting access token", response.getStatusCode() + "", response.getIntuit_tid(), response); } ObjectReader reader = mapper.readerFor(BearerTokenResponse.class); BearerTokenResponse bearerTokenResponse = reader.readValue(response.getContent()); bearerTokenResponse.setIntuit_tid(response.getIntuit_tid()); return bearerTokenResponse; } catch (OAuthException ex) { logger.error("OAuthException while retrieving bearer tokens: " + ex.getResponseContent()); throw new OAuthException("Failed getting access token", ex.getStatusCode() + "", ex.getIntuit_tid(), ex.getResponse()); } catch (Exception ex) { logger.error("Exception while retrieving bearer tokens", ex); throw new OAuthException(ex.getMessage(), ex); } } }
OAuth2PlatformClient { public BearerTokenResponse retrieveBearerTokens(String authCode, String redirectURI) throws OAuthException { logger.debug("Enter OAuth2PlatformClient::retrieveBearerTokens"); try { HttpRequestClient client = new HttpRequestClient(oauth2Config.getProxyConfig()); Request request = new Request.RequestBuilder(MethodType.POST, oauth2Config.getIntuitBearerTokenEndpoint()) .requiresAuthentication(true) .authString(getAuthHeader()) .postParams(getUrlParameters(null, authCode, redirectURI)) .build(); Response response = client.makeRequest(request); logger.debug("Response Code : "+ response.getStatusCode()); logger.debug("intuit_tid : "+ response.getIntuit_tid()); if (response.getStatusCode() != 200) { logger.debug("failed getting access token"); logger.debug("Response content : "+ response.getContent()); throw new OAuthException("Failed getting access token", response.getStatusCode() + "", response.getIntuit_tid(), response); } ObjectReader reader = mapper.readerFor(BearerTokenResponse.class); BearerTokenResponse bearerTokenResponse = reader.readValue(response.getContent()); bearerTokenResponse.setIntuit_tid(response.getIntuit_tid()); return bearerTokenResponse; } catch (OAuthException ex) { logger.error("OAuthException while retrieving bearer tokens: " + ex.getResponseContent()); throw new OAuthException("Failed getting access token", ex.getStatusCode() + "", ex.getIntuit_tid(), ex.getResponse()); } catch (Exception ex) { logger.error("Exception while retrieving bearer tokens", ex); throw new OAuthException(ex.getMessage(), ex); } } OAuth2PlatformClient(OAuth2Config oauth2Config); protected  OAuth2PlatformClient(); }
OAuth2PlatformClient { public BearerTokenResponse retrieveBearerTokens(String authCode, String redirectURI) throws OAuthException { logger.debug("Enter OAuth2PlatformClient::retrieveBearerTokens"); try { HttpRequestClient client = new HttpRequestClient(oauth2Config.getProxyConfig()); Request request = new Request.RequestBuilder(MethodType.POST, oauth2Config.getIntuitBearerTokenEndpoint()) .requiresAuthentication(true) .authString(getAuthHeader()) .postParams(getUrlParameters(null, authCode, redirectURI)) .build(); Response response = client.makeRequest(request); logger.debug("Response Code : "+ response.getStatusCode()); logger.debug("intuit_tid : "+ response.getIntuit_tid()); if (response.getStatusCode() != 200) { logger.debug("failed getting access token"); logger.debug("Response content : "+ response.getContent()); throw new OAuthException("Failed getting access token", response.getStatusCode() + "", response.getIntuit_tid(), response); } ObjectReader reader = mapper.readerFor(BearerTokenResponse.class); BearerTokenResponse bearerTokenResponse = reader.readValue(response.getContent()); bearerTokenResponse.setIntuit_tid(response.getIntuit_tid()); return bearerTokenResponse; } catch (OAuthException ex) { logger.error("OAuthException while retrieving bearer tokens: " + ex.getResponseContent()); throw new OAuthException("Failed getting access token", ex.getStatusCode() + "", ex.getIntuit_tid(), ex.getResponse()); } catch (Exception ex) { logger.error("Exception while retrieving bearer tokens", ex); throw new OAuthException(ex.getMessage(), ex); } } OAuth2PlatformClient(OAuth2Config oauth2Config); protected  OAuth2PlatformClient(); BearerTokenResponse retrieveBearerTokens(String authCode, String redirectURI); BearerTokenResponse refreshToken(String refreshToken); PlatformResponse revokeToken(String token); UserInfoResponse getUserInfo(String accessToken); boolean validateIDToken(String idToken); }
OAuth2PlatformClient { public BearerTokenResponse retrieveBearerTokens(String authCode, String redirectURI) throws OAuthException { logger.debug("Enter OAuth2PlatformClient::retrieveBearerTokens"); try { HttpRequestClient client = new HttpRequestClient(oauth2Config.getProxyConfig()); Request request = new Request.RequestBuilder(MethodType.POST, oauth2Config.getIntuitBearerTokenEndpoint()) .requiresAuthentication(true) .authString(getAuthHeader()) .postParams(getUrlParameters(null, authCode, redirectURI)) .build(); Response response = client.makeRequest(request); logger.debug("Response Code : "+ response.getStatusCode()); logger.debug("intuit_tid : "+ response.getIntuit_tid()); if (response.getStatusCode() != 200) { logger.debug("failed getting access token"); logger.debug("Response content : "+ response.getContent()); throw new OAuthException("Failed getting access token", response.getStatusCode() + "", response.getIntuit_tid(), response); } ObjectReader reader = mapper.readerFor(BearerTokenResponse.class); BearerTokenResponse bearerTokenResponse = reader.readValue(response.getContent()); bearerTokenResponse.setIntuit_tid(response.getIntuit_tid()); return bearerTokenResponse; } catch (OAuthException ex) { logger.error("OAuthException while retrieving bearer tokens: " + ex.getResponseContent()); throw new OAuthException("Failed getting access token", ex.getStatusCode() + "", ex.getIntuit_tid(), ex.getResponse()); } catch (Exception ex) { logger.error("Exception while retrieving bearer tokens", ex); throw new OAuthException(ex.getMessage(), ex); } } OAuth2PlatformClient(OAuth2Config oauth2Config); protected  OAuth2PlatformClient(); BearerTokenResponse retrieveBearerTokens(String authCode, String redirectURI); BearerTokenResponse refreshToken(String refreshToken); PlatformResponse revokeToken(String token); UserInfoResponse getUserInfo(String accessToken); boolean validateIDToken(String idToken);  }