@Test(expectedExceptions = OpenIdException.class) public void getUserInfoThrowsOpenIdExceptionOnErrorStatus() throws JsonProcessingException, OpenIdException { ObjectWriter writer = mapper.writerFor(UserInfoResponse.class); Response mockResponse = new Response( IOUtils.toInputStream(writer.writeValueAsString(new UserInfoResponse()), StandardCharsets.UTF_8), 500, intuit_tid); mockedHttpRequestClient.setMockResponse(mockResponse); oAuth2PlatformClient.getUserInfo("test-token"); }
public UserInfoResponse getUserInfo(String accessToken) throws OpenIdException { logger.debug("Enter OAuth2PlatformClient::getUserInfo"); try { HttpRequestClient client = new HttpRequestClient(oauth2Config.getProxyConfig()); Request request = new Request.RequestBuilder(MethodType.GET, oauth2Config.getUserProfileEndpoint()) .requiresAuthentication(true) .authString("Bearer " + accessToken) .build(); Response response = client.makeRequest(request); logger.debug("Response Code : "+ response.getStatusCode()); logger.debug("intuit_tid: " + response.getIntuit_tid()); if (response.getStatusCode() == 200) { ObjectReader reader = mapper.readerFor(UserInfoResponse.class); UserInfoResponse userInfoResponse = reader.readValue(response.getContent()); userInfoResponse.setIntuit_tid(response.getIntuit_tid()); return userInfoResponse; } else { logger.debug("failed getting user info"); throw new OpenIdException("failed getting user info", response.getStatusCode() + "", response.getIntuit_tid(), response); } } catch (OpenIdException ex) { logger.error("OpenIdException while retrieving user info: " + ex.getResponseContent()); throw new OpenIdException("failed getting user info", ex.getStatusCode() + "", ex.getIntuit_tid(), ex.getResponse()); } catch (Exception ex) { logger.error("Exception while retrieving user info ", ex); throw new OpenIdException(ex.getMessage(), ex); } }
OAuth2PlatformClient { public UserInfoResponse getUserInfo(String accessToken) throws OpenIdException { logger.debug("Enter OAuth2PlatformClient::getUserInfo"); try { HttpRequestClient client = new HttpRequestClient(oauth2Config.getProxyConfig()); Request request = new Request.RequestBuilder(MethodType.GET, oauth2Config.getUserProfileEndpoint()) .requiresAuthentication(true) .authString("Bearer " + accessToken) .build(); Response response = client.makeRequest(request); logger.debug("Response Code : "+ response.getStatusCode()); logger.debug("intuit_tid: " + response.getIntuit_tid()); if (response.getStatusCode() == 200) { ObjectReader reader = mapper.readerFor(UserInfoResponse.class); UserInfoResponse userInfoResponse = reader.readValue(response.getContent()); userInfoResponse.setIntuit_tid(response.getIntuit_tid()); return userInfoResponse; } else { logger.debug("failed getting user info"); throw new OpenIdException("failed getting user info", response.getStatusCode() + "", response.getIntuit_tid(), response); } } catch (OpenIdException ex) { logger.error("OpenIdException while retrieving user info: " + ex.getResponseContent()); throw new OpenIdException("failed getting user info", ex.getStatusCode() + "", ex.getIntuit_tid(), ex.getResponse()); } catch (Exception ex) { logger.error("Exception while retrieving user info ", ex); throw new OpenIdException(ex.getMessage(), ex); } } }
OAuth2PlatformClient { public UserInfoResponse getUserInfo(String accessToken) throws OpenIdException { logger.debug("Enter OAuth2PlatformClient::getUserInfo"); try { HttpRequestClient client = new HttpRequestClient(oauth2Config.getProxyConfig()); Request request = new Request.RequestBuilder(MethodType.GET, oauth2Config.getUserProfileEndpoint()) .requiresAuthentication(true) .authString("Bearer " + accessToken) .build(); Response response = client.makeRequest(request); logger.debug("Response Code : "+ response.getStatusCode()); logger.debug("intuit_tid: " + response.getIntuit_tid()); if (response.getStatusCode() == 200) { ObjectReader reader = mapper.readerFor(UserInfoResponse.class); UserInfoResponse userInfoResponse = reader.readValue(response.getContent()); userInfoResponse.setIntuit_tid(response.getIntuit_tid()); return userInfoResponse; } else { logger.debug("failed getting user info"); throw new OpenIdException("failed getting user info", response.getStatusCode() + "", response.getIntuit_tid(), response); } } catch (OpenIdException ex) { logger.error("OpenIdException while retrieving user info: " + ex.getResponseContent()); throw new OpenIdException("failed getting user info", ex.getStatusCode() + "", ex.getIntuit_tid(), ex.getResponse()); } catch (Exception ex) { logger.error("Exception while retrieving user info ", ex); throw new OpenIdException(ex.getMessage(), ex); } } OAuth2PlatformClient(OAuth2Config oauth2Config); protected  OAuth2PlatformClient(); }
OAuth2PlatformClient { public UserInfoResponse getUserInfo(String accessToken) throws OpenIdException { logger.debug("Enter OAuth2PlatformClient::getUserInfo"); try { HttpRequestClient client = new HttpRequestClient(oauth2Config.getProxyConfig()); Request request = new Request.RequestBuilder(MethodType.GET, oauth2Config.getUserProfileEndpoint()) .requiresAuthentication(true) .authString("Bearer " + accessToken) .build(); Response response = client.makeRequest(request); logger.debug("Response Code : "+ response.getStatusCode()); logger.debug("intuit_tid: " + response.getIntuit_tid()); if (response.getStatusCode() == 200) { ObjectReader reader = mapper.readerFor(UserInfoResponse.class); UserInfoResponse userInfoResponse = reader.readValue(response.getContent()); userInfoResponse.setIntuit_tid(response.getIntuit_tid()); return userInfoResponse; } else { logger.debug("failed getting user info"); throw new OpenIdException("failed getting user info", response.getStatusCode() + "", response.getIntuit_tid(), response); } } catch (OpenIdException ex) { logger.error("OpenIdException while retrieving user info: " + ex.getResponseContent()); throw new OpenIdException("failed getting user info", ex.getStatusCode() + "", ex.getIntuit_tid(), ex.getResponse()); } catch (Exception ex) { logger.error("Exception while retrieving user info ", ex); throw new OpenIdException(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 UserInfoResponse getUserInfo(String accessToken) throws OpenIdException { logger.debug("Enter OAuth2PlatformClient::getUserInfo"); try { HttpRequestClient client = new HttpRequestClient(oauth2Config.getProxyConfig()); Request request = new Request.RequestBuilder(MethodType.GET, oauth2Config.getUserProfileEndpoint()) .requiresAuthentication(true) .authString("Bearer " + accessToken) .build(); Response response = client.makeRequest(request); logger.debug("Response Code : "+ response.getStatusCode()); logger.debug("intuit_tid: " + response.getIntuit_tid()); if (response.getStatusCode() == 200) { ObjectReader reader = mapper.readerFor(UserInfoResponse.class); UserInfoResponse userInfoResponse = reader.readValue(response.getContent()); userInfoResponse.setIntuit_tid(response.getIntuit_tid()); return userInfoResponse; } else { logger.debug("failed getting user info"); throw new OpenIdException("failed getting user info", response.getStatusCode() + "", response.getIntuit_tid(), response); } } catch (OpenIdException ex) { logger.error("OpenIdException while retrieving user info: " + ex.getResponseContent()); throw new OpenIdException("failed getting user info", ex.getStatusCode() + "", ex.getIntuit_tid(), ex.getResponse()); } catch (Exception ex) { logger.error("Exception while retrieving user info ", ex); throw new OpenIdException(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);  }