private String getFacebookProfileId(OAuthResourceResponse resourceResponse) throws IOException { String resourceResponseBody = resourceResponse.getBody(); ObjectMapper objectMapper = new ObjectMapper(); JsonNode jsonNode = objectMapper.readTree(resourceResponseBody); JsonNode idNode = jsonNode.get("id"); return (idNode != null) ? idNode.asText() : null; }
public OAuthPrincipal principal(String accessToken) throws CasOAuthException { OAuthPrincipal p = _accessTokenCache.get(accessToken); if (p != null) return p; try { OAuthClientRequest cr = new OAuthBearerClientRequest(casServerUrl + "oauth2.0/profile") .setAccessToken(accessToken) .buildQueryMessage(); OAuthClient client = new OAuthClient(new URLConnectionClient()); OAuthResourceResponse cres = client.resource(cr, "GET", OAuthResourceResponse.class); String body = cres.getBody(); p = createJsonPrincipal(body, accessToken); _accessTokenCache.put(accessToken, p); } catch (Exception e) { throw new CasOAuthException("verifyCode", e); } return p; }
public String getUserInfo(String accessToken) throws FcConnectException { OAuthClient oAuthClient = new OAuthClient(new URLConnectionClient()); // récupération du profil client OAuthClientRequest bearerClientRequest; try { bearerClientRequest = new OAuthBearerClientRequest(configuration.getUserInfoUri()) .setAccessToken(accessToken) .buildHeaderMessage(); OAuthResourceResponse resourceResponse = oAuthClient.resource( bearerClientRequest, OAuth.HttpMethod.GET, OAuthResourceResponse.class); return resourceResponse.getBody(); } catch (OAuthSystemException e) { throw new FcConnectException("Error during userInfo request building : ", e); } catch (OAuthProblemException e) { throw new FcConnectException("Error during userInfo retrieving : ", e); } }