Ejemplo n.º 1
0
        /**
         * Add some of the parameters needed to request access to a protected
         * resource, if they aren't already in the message.
         *
         * @throws IOException
         * @throws URISyntaxException
         */
        public void addRequiredParameters(OAuthAccessor accessor)
        {
            Dictionary <string, string> pMap = OAuth.newMap(parameters);

            if (!pMap.ContainsKey(OAuth.OAUTH_TOKEN) && accessor.accessToken != null)
            {
                addParameter(OAuth.OAUTH_TOKEN, accessor.accessToken);
            }
            OAuthConsumer consumer = accessor.consumer;

            if (!pMap.ContainsKey(OAuth.OAUTH_CONSUMER_KEY))
            {
                addParameter(OAuth.OAUTH_CONSUMER_KEY, consumer.consumerKey);
            }
            string signatureMethod;

            if (!pMap.TryGetValue(OAuth.OAUTH_SIGNATURE_METHOD, out signatureMethod))
            {
                signatureMethod = (string)consumer.getProperty(OAuth.OAUTH_SIGNATURE_METHOD) ?? OAuth.HMAC_SHA1;
                addParameter(OAuth.OAUTH_SIGNATURE_METHOD, signatureMethod);
            }
            if (!pMap.ContainsKey(OAuth.OAUTH_TIMESTAMP))
            {
                addParameter(OAuth.OAUTH_TIMESTAMP, UnixTime.ToInt64(DateTime.UtcNow).ToString());
            }
            if (!pMap.ContainsKey(OAuth.OAUTH_NONCE))
            {
                addParameter(OAuth.OAUTH_NONCE, Crypto.getRandomString(OAuth.OAUTH_NONCE_LENGTH));
            }

            sign(accessor);
        }
Ejemplo n.º 2
0
        public OAuthMessage newRequestMessage(String method, String url,
                                              List <OAuth.Parameter> parameters)
        {
            if (method == null)
            {
                method = (String)getProperty("httpMethod") ?? ((String)consumer.getProperty("httpMethod") ?? "GET");
            }
            OAuthMessage message = new OAuthMessage(method, url, parameters);

            message.addRequiredParameters(this);
            return(message);
        }