Examples of OAuthMessage


Examples of net.oauth.OAuthMessage

  /**
   * Exchanges an authorized request token with an access token.
   */
  private void doExchangeToken(HttpServletRequest req, HttpServletResponse resp)
      throws IOException {
    OAuthMessage message = new HttpRequestMessage(req, req.getRequestURL().toString());

    String requestToken = message.getToken();
    OAuthAccessor accessor;
    try {
      accessor = tokenContainer.getRequestTokenAccessor(requestToken);
    } catch (OAuthProblemException e) {
      LOG.info("Request token unknown", e);
View Full Code Here

Examples of net.oauth.OAuthMessage

  /**
   * Perform full Auth dance and print tokens.
   */
  private void doAllTokens(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    OAuthMessage message = new HttpRequestMessage(req, req.getRequestURL().toString());
    String requestToken = message.getToken();
    if (requestToken == null) {
      OAuthConsumer consumer =
          new OAuthConsumer("", ANONYMOUS_TOKEN, ANONYMOUS_TOKEN_SECRET, serviceProvider);
      OAuthAccessor accessor = tokenContainer.generateRequestToken(consumer);
      String url = accessor.consumer.serviceProvider.userAuthorizationURL
View Full Code Here

Examples of net.oauth.OAuthMessage

    // Perform the exchange.
    String accessToken = null;
    String tokenSecret = null;
    try {
      OAuthMessage message =
          oauthClient.invoke(accessor, GET, accessor.consumer.serviceProvider.accessTokenURL, null);
      accessToken = message.getToken();
      tokenSecret = message.getParameter(OAuth.OAUTH_TOKEN_SECRET);
    } catch (IOException e) {
      LOG.warning("Failed to retrieve access token: " + e.getMessage());
    } catch (OAuthException e) {
      LOG.warning("Failed to retrieve access token: " + e.getMessage());
    } catch (URISyntaxException e) {
View Full Code Here

Examples of net.oauth.OAuthMessage

    accessor.accessToken = userProfile.getAccessToken();
    accessor.tokenSecret = userProfile.getTokenSecret();

    // Send request and receive response from service provider.
    String messageString = "";
    OAuthMessage message;
    try {
      message = oauthClient.invoke(accessor, method, url, queryParameters);
      messageString = message.readBodyAsString();
    } catch (IOException e) {
      LOG.severe("Response message has no body: " + e);
      throw new OAuthServiceException(e);
    } catch (URISyntaxException e) {
      LOG.severe("Unable to fetch resources. Invalid url: " + e);
View Full Code Here

Examples of net.oauth.OAuthMessage

    for (Map.Entry<String, String[]> entry : requestParams.entrySet()) {
      for (String value : entry.getValue()) {
        params.add(new OAuth.Parameter(entry.getKey(), value));
      }
    }
    OAuthMessage message = new OAuthMessage(POST, requestUrl, params);

    // Compute and check the hash of the body.
    try {
      MessageDigest md = MessageDigest.getInstance(SHA_1);
      byte[] hash = md.digest(jsonBody.getBytes(UTF_8));
      String encodedHash = new String(Base64.encodeBase64(hash, false), UTF_8);
      if (!encodedHash.equals(message.getParameter(OAUTH_BODY_HASH))) {
        throw new IllegalArgumentException(
            "Body hash does not match. Expected: " + encodedHash + ", provided: "
                + message.getParameter(OAUTH_BODY_HASH));
      }

      OAuthAccessor accessor = consumerData.getAccessor();
      if (LOG.isLoggable(Level.FINE)) {
        LOG.fine("Signature base string: " + OAuthSignatureMethod.getBaseString(message));
View Full Code Here

Examples of net.oauth.OAuthMessage

        request.headers.add(new SimpleEntry<String, String>("oauth_version", "1.0"));
        responseStream =
            httpFetcher.execute(request, Collections.<String, Object>emptyMap()).getBody();
      } else {
        OAuthAccessor accessor = consumerDataObj.getAccessor();
        OAuthMessage message = accessor.newRequestMessage("POST", rpcServerUrl, null, bodyStream);
        message.getHeaders().add(
            new SimpleEntry<String, String>(HttpMessage.CONTENT_TYPE, JSON_MIME_TYPE));
        message.getHeaders().add(new SimpleEntry<String, String>("oauth_version", "1.0"));
        OAuthClient client = new OAuthClient(httpFetcher);
        responseStream = client.invoke(message, net.oauth.ParameterStyle.BODY).getBodyAsStream();
      }

      String responseString = HttpFetcher.readInputStream(responseStream);
View Full Code Here

Examples of net.oauth.OAuthMessage

   * @return a URL for the given JSON string, and the required OAuth parameters.
   */
  public static String createOAuthUrlString(
      String jsonBody, String rpcServerUrl, OAuthAccessor accessor)
      throws IOException, URISyntaxException, OAuthException {
    OAuthMessage message =
        new OAuthMessage(POST, rpcServerUrl, Collections.<SimpleEntry<String, String>>emptyList());

    // Compute the hash of the body.
    byte[] rawBody = jsonBody.getBytes(UTF_8);
    byte[] hash = DigestUtils.sha(rawBody);
    byte[] encodedHash = Base64.encodeBase64(hash);
    message.addParameter(OAUTH_BODY_HASH, new String(encodedHash, UTF_8));

    // Add other parameters.

    message.addRequiredParameters(accessor);
    if (LOG.isLoggable(Level.FINE)) {
      LOG.fine("Signature base string: " + OAuthSignatureMethod.getBaseString(message));
    }

    // Construct the resulting URL.
    StringBuilder sb = new StringBuilder(rpcServerUrl);
    char connector = '?';
    for (Map.Entry<String, String> p : message.getParameters()) {
      if (!p.getKey().equals(jsonBody)) {
        sb.append(connector);
        sb.append(URLEncoder.encode(p.getKey(), UTF_8));
        sb.append('=');
        sb.append(URLEncoder.encode(p.getValue(), UTF_8));
View Full Code Here

Examples of net.oauth.OAuthMessage

    }
   
    private static String doGetAuthorizationHeader(OAuthAccessor accessor,
            String method, String requestURI, Map<String, String> parameters) {
        try {
            OAuthMessage msg = accessor.newRequestMessage(method, requestURI, parameters.entrySet());
            return msg.getAuthorizationHeader(null);
        } catch (Exception ex) {
            throw new ClientWebApplicationException(ex);
        }
    }
View Full Code Here

Examples of org.apache.amber.oauth2.common.message.OAuthMessage

        params.put("empty_param", "");
        params.put("null_param", null);
        params.put("", "some_value");
        params.put(null, "some_value");

        OAuthMessage message = new DummyOAuthMessage("http://www.example.com/rd", 200);

        app.applyOAuthParameters(message, params);

        String body = message.getBody();
        Assert.assertTrue(body.contains("3600"));
        Assert.assertTrue(body.contains("token_authz"));
        Assert.assertTrue(body.contains("code_"));
        Assert.assertTrue(body.contains("read"));
        Assert.assertTrue(body.contains("state"));
View Full Code Here

Examples of org.apache.amber.oauth2.common.message.OAuthMessage

        params.put(OAuth.OAUTH_SCOPE, "read");
        params.put(OAuth.OAUTH_STATE, "state");
        params.put("empty_param", "");
        params.put("null_param", null);

        OAuthMessage message = new DummyOAuthMessage("http://www.example.com/rd", 200);

        app.applyOAuthParameters(message, params);

        String locationURI = message.getLocationUri();
        Assert.assertTrue(locationURI.contains("3600"));
        Assert.assertTrue(locationURI.contains("token_authz"));
        Assert.assertTrue(locationURI.contains("code_"));
        Assert.assertTrue(locationURI.contains("read"));
        Assert.assertTrue(locationURI.contains("state"));
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.