Package oauth.signpost.http

Examples of oauth.signpost.http.HttpParameters


        String[] parts = result.split("\\?");
        assertEquals("parameters are missing", 2, parts.length);
        assertEquals("http://www.example.com", parts[0]);

        HttpParameters params = OAuth.decodeForm(parts[1]);
        assertAllOAuthParametersExist(params);

        assertEquals("1", params.getFirst("q"));
    }
View Full Code Here


        }
        if (consumerSecret == null) {
            throw new OAuthExpectationFailedException("consumer secret not set");
        }

        requestParameters = new HttpParameters();
        try {
            if (additionalParameters != null) {
                requestParameters.putAll(additionalParameters, false);
            }
            collectHeaderParameters(request, requestParameters);
View Full Code Here

    /**
     * Collects OAuth Authorization header parameters as per OAuth Core 1.0 spec
     * section 9.1.1
     */
    protected void collectHeaderParameters(HttpRequest request, HttpParameters out) {
        HttpParameters headerParams = OAuth.oauthHeaderToParamsMap(request.getHeader(OAuth.HTTP_AUTHORIZATION_HEADER));
        out.putAll(headerParams, false);
    }
View Full Code Here

            sb.append(requestParameters.getAsHeaderElement("realm"));
            sb.append(", ");
        }

        // add all (x_)oauth parameters
        HttpParameters oauthParams = requestParameters.getOAuthParameters();
        oauthParams.put(OAuth.OAUTH_SIGNATURE, signature, true);

        Iterator<String> iter = oauthParams.keySet().iterator();
        while (iter.hasNext()) {
            String key = iter.next();
            sb.append(oauthParams.getAsHeaderElement(key));
            if (iter.hasNext()) {
                sb.append(", ");
            }
        }
View Full Code Here

        // verify that all custom params are properly read and passed to the
        // message signer
        ArgumentMatcher<HttpParameters> hasAllParameters = new ArgumentMatcher<HttpParameters>() {
            public boolean matches(Object argument) {
                HttpParameters params = (HttpParameters) argument;
                assertEquals("1 1", params.getFirst("a", true));
                assertEquals("2 2", params.getFirst("b", true));
                assertEquals("http://example.com", params.getFirst("realm", true));
                assertEquals("12%345", params.getFirst("oauth_token", true));
                // signature should be dropped, not valid to pre-set
                assertNull(params.getFirst("oauth_signature"));
                return true;
            }
        };

        verify(signer).sign(same(request), argThat(hasAllParameters));
View Full Code Here

        when(request.getRequestUrl()).thenReturn("http://example.com?a=1");

        OAuthMessageSigner signer = mock(HmacSha1MessageSigner.class);
        consumer.setMessageSigner(signer);

        HttpParameters params = new HttpParameters();
        params.put("oauth_callback", "http://mycallback");
        consumer.setAdditionalParameters(params);

        consumer.sign(request);

        // verify that all custom params are properly read and passed to the
        // message signer
        ArgumentMatcher<HttpParameters> hasParameters = new ArgumentMatcher<HttpParameters>() {
            public boolean matches(Object argument) {
                HttpParameters params = (HttpParameters) argument;
                assertEquals("http://mycallback", params.getFirst("oauth_callback"));
                assertEquals("1", params.getFirst("a"));
                return true;
            }
        };

        verify(signer).sign(same(request), argThat(hasParameters));
View Full Code Here

            ArgumentCaptor<String> arg1 = ArgumentCaptor.forClass(String.class);
            ArgumentCaptor<String> arg2 = ArgumentCaptor.forClass(String.class);

            verify(httpGetMock).setHeader(eq("Authorization"), arg1.capture());
            verify(httpGetMockWithQueryString).setHeader(eq("Authorization"), arg2.capture());
            HttpParameters headerMap1 = OAuth.oauthHeaderToParamsMap(arg1.getValue());
            HttpParameters headerMap2 = OAuth.oauthHeaderToParamsMap(arg2.getValue());
            assertThat(headerMap1.getFirst(OAuth.OAUTH_NONCE), not(equalTo(headerMap2.getFirst(OAuth.OAUTH_NONCE))));
        }
    }
View Full Code Here

    public String writeSignature(String signature, HttpRequest request,
            HttpParameters requestParameters) {

        // add all (x_)oauth parameters
        HttpParameters oauthParams = requestParameters.getOAuthParameters();
        oauthParams.put(OAuth.OAUTH_SIGNATURE, signature, true);

        Iterator<String> iter = oauthParams.keySet().iterator();

        // add the first query parameter (we always have at least the signature)
        String firstKey = iter.next();
        StringBuilder sb = new StringBuilder(OAuth.addQueryString(request.getRequestUrl(),
            oauthParams.getAsQueryString(firstKey)));

        while (iter.hasNext()) {
            sb.append("&");
            String key = iter.next();
            sb.append(oauthParams.getAsQueryString(key));
        }

        String signedUrl = sb.toString();

        request.setRequestUrl(signedUrl);
View Full Code Here

    private class HasValuesPercentEncoded extends ArgumentMatcher<String> {

        @Override
        public boolean matches(Object argument) {
            String oauthHeader = (String) argument;
            HttpParameters params = OAuth.oauthHeaderToParamsMap(oauthHeader);
            assertEquals("1%252", params.getFirst("oauth_consumer_key"));
            assertEquals("3%204", params.getFirst("oauth_token"));
            return true;
        }
View Full Code Here

                + rfc3986UnreservedCharacters, OAuth.formEncode(params.entrySet()));
    }

    @Test
    public void shouldCorrectlyFormDecodeParameters() {
        HttpParameters params = OAuth.decodeForm("one=" + reservedCharactersEncoded
                + "&" + "one=another&"
                + reservedCharactersEncoded + "=" + rfc3986UnreservedCharacters);

        assertTrue(params.size() == 3);

        Iterator<String> iter1 = params.get("one").iterator();
        assertEquals(rfc3986ReservedCharacters, iter1.next());
        assertEquals("another", iter1.next());

        Iterator<String> iter2 = params.get(rfc3986ReservedCharacters).iterator();
        assertEquals(rfc3986UnreservedCharacters, iter2.next());
    }
View Full Code Here

TOP

Related Classes of oauth.signpost.http.HttpParameters

Copyright © 2018 www.massapicom. 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.