List of usage examples for org.springframework.security.oauth2.client OAuth2RestTemplate getOAuth2ClientContext
public OAuth2ClientContext getOAuth2ClientContext()
From source file:com.feedeo.rest.client.AbstractOAuth2RestClient.java
public void setAccessToken(String accessToken) { OAuth2AccessToken oAuth2AccessToken = new DefaultOAuth2AccessToken(accessToken); OAuth2RestTemplate restOperations = (OAuth2RestTemplate) getRestOperations(); restOperations.getOAuth2ClientContext().setAccessToken(oAuth2AccessToken); }
From source file:sparklr.common.AbstractAuthorizationCodeProviderTests.java
private void verifyAuthorizationPage(OAuth2RestTemplate restTemplate, String location) { final AtomicReference<String> confirmationPage = new AtomicReference<String>(); AuthorizationCodeAccessTokenProvider provider = new AuthorizationCodeAccessTokenProvider() { @Override//from w w w . ja v a 2s. c o m protected ResponseExtractor<ResponseEntity<Void>> getAuthorizationResponseExtractor() { return new ResponseExtractor<ResponseEntity<Void>>() { public ResponseEntity<Void> extractData(ClientHttpResponse response) throws IOException { confirmationPage .set(StreamUtils.copyToString(response.getBody(), Charset.forName("UTF-8"))); return new ResponseEntity<Void>(response.getHeaders(), response.getStatusCode()); } }; } }; try { provider.obtainAuthorizationCode(restTemplate.getResource(), restTemplate.getOAuth2ClientContext().getAccessTokenRequest()); } catch (UserApprovalRequiredException e) { // ignore } String page = confirmationPage.get(); verifyAuthorizationPage(page); }
From source file:org.springframework.cloud.security.oauth2.UserInfoTokenServices.java
private Map<String, Object> getMap(String path, String accessToken) { logger.info("Getting user info from: " + path); BaseOAuth2ProtectedResourceDetails resource = new BaseOAuth2ProtectedResourceDetails(); resource.setClientId(clientId);// w ww .j a va 2 s .co m OAuth2RestTemplate restTemplate = new OAuth2RestTemplate(resource); restTemplate.getOAuth2ClientContext().setAccessToken(new DefaultOAuth2AccessToken(accessToken)); @SuppressWarnings("rawtypes") Map map = restTemplate.getForEntity(path, Map.class).getBody(); @SuppressWarnings("unchecked") Map<String, Object> result = map; return result; }