public static String getBaseString(OAuthMessage message)
        {
            List <OAuth.Parameter> parameters;
            String url = message.URL;
            int    q   = url.IndexOf('?');

            if (q < 0)
            {
                parameters = message.getParameters();
            }
            else
            {
                // Combine the URL query string with the other parameters:
                parameters = new List <OAuth.Parameter>();
                parameters.AddRange(OAuth.decodeForm(url.Substring(q + 1)));
                parameters.AddRange(message.getParameters());
                url = url.Substring(0, q);
            }
            return(Rfc3986.Encode(message.method.ToUpper()) + '&'
                   + Rfc3986.Encode(normalizeUrl(url)) + '&'
                   + Rfc3986.Encode(normalizeParameters(parameters)));
        }
    /**
     * Signs the URL associated with the passed request object using the passed
     * consumer key and secret in accordance with the OAuth specification and
     * appends signature and other required parameters to the URL as query
     * string parameters.
     *
     * @param  request OpenSocialHttpRequest object which contains both the URL
     *         to sign as well as the POST body which must be included as a
     *         parameter when signing POST requests
     * @param  consumerKey Application key assigned and used by containers to
     *         uniquely identify applications
     * @param  consumerSecret Secret key shared between application owner and
     *         container. Used to generate the signature which is attached to
     *         the request so containers can verify the authenticity of the
     *         requests made by the client application.
     * @throws OAuthException
     * @throws IOException
     * @throws URISyntaxException
     */
    public static void signRequest(
        OpenSocialHttpRequest request, String consumerKey, String consumerSecret)
    {
        String        postBody      = request.getPostBody();
        String        requestMethod = request.getMethod();
        OpenSocialUrl requestUrl    = request.getUrl();

        if (!String.IsNullOrEmpty(consumerKey) && !String.IsNullOrEmpty(consumerSecret))
        {
            OAuthMessage message =
                new OAuthMessage(requestMethod, requestUrl.ToString(), null);

            if (!String.IsNullOrEmpty(postBody))
            {
                message.addParameter(postBody, "");
            }

            OAuthConsumer consumer =
                new OAuthConsumer(null, consumerKey, consumerSecret, null);
            consumer.setProperty(OAuth.OAUTH_SIGNATURE_METHOD, OAuth.HMAC_SHA1);

            OAuthAccessor accessor = new OAuthAccessor(consumer);
            accessor.accessToken = "";

            message.addRequiredParameters(accessor);

            foreach (var p in message.getParameters())
            {
                if (!p.Key.Equals(postBody))
                {
                    requestUrl.addQueryStringParameter(
                        OAuth.percentEncode(new List <string> {
                        p.Key
                    }),
                        OAuth.percentEncode(new List <string> {
                        p.Value
                    }));
                }
            }
        }
    }
Beispiel #3
0
 public static List <OAuth.Parameter> getParameters(OAuthMessage message)
 {
     return(message.getParameters());
 }
Beispiel #4
0
 public static String getBaseString(OAuthMessage message)
 {
     List<OAuth.Parameter> parameters;
     String url = message.URL;
     int q = url.IndexOf('?');
     if (q < 0)
     {
         parameters = message.getParameters();
     }
     else
     {
         // Combine the URL query string with the other parameters:
         parameters = new List<OAuth.Parameter>();
         parameters.AddRange(OAuth.decodeForm(url.Substring(q + 1)));
         parameters.AddRange(message.getParameters());
         url = url.Substring(0, q);
     }
     return Rfc3986.Encode(message.method.ToUpper()) + '&'
            + Rfc3986.Encode(normalizeUrl(url)) + '&'
            + Rfc3986.Encode(normalizeParameters(parameters));
 }