Exemplo n.º 1
0
 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;
 }
Exemplo n.º 2
0
  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;
  }
Exemplo n.º 3
0
  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);
    }
  }