public static String addQueryParameters(String url, Map<String, String> params) { String[] kvPairs = new String[params.size() * 2]; int idx = 0; for (String key : params.keySet()) { kvPairs[idx] = key; kvPairs[idx + 1] = params.get(key); idx += 2; } return addQueryParameters(url, kvPairs); }
@Test public void shouldCorrectlyAppendQueryParameters() { String url1 = "http://www.example.com"; assertEquals("http://www.example.com?a=1&b=2", OAuth.addQueryParameters(url1, "a", "1", "b", "2")); String url2 = "http://www.example.com?x=1"; assertEquals("http://www.example.com?x=1&a=1&b=2", OAuth.addQueryParameters(url2, "a", "1", "b", "2")); Map<String, String> params = new LinkedHashMap<String, String>(); params.put("a", "1"); params.put("b", "2"); assertEquals("http://www.example.com?x=1&a=1&b=2", OAuth.addQueryParameters(url2, params)); }
public synchronized String retrieveRequestToken(OAuthConsumer consumer, String callbackUrl, String... customOAuthParams) throws OAuthMessageSignerException, OAuthNotAuthorizedException, OAuthExpectationFailedException, OAuthCommunicationException { // invalidate current credentials, if any consumer.setTokenWithSecret(null, null); // 1.0a expects the callback to be sent while getting the request token. // 1.0 service providers would simply ignore this parameter. HttpParameters params = new HttpParameters(); params.putAll(customOAuthParams, true); params.put(OAuth.OAUTH_CALLBACK, callbackUrl, true); retrieveToken(consumer, requestTokenEndpointUrl, params); String callbackConfirmed = responseParameters.getFirst(OAuth.OAUTH_CALLBACK_CONFIRMED); responseParameters.remove(OAuth.OAUTH_CALLBACK_CONFIRMED); isOAuth10a = Boolean.TRUE.toString().equals(callbackConfirmed); // 1.0 service providers expect the callback as part of the auth URL, // Do not send when 1.0a. if (isOAuth10a) { return OAuth.addQueryParameters(authorizationWebsiteUrl, OAuth.OAUTH_TOKEN, consumer.getToken()); } else { return OAuth.addQueryParameters(authorizationWebsiteUrl, OAuth.OAUTH_TOKEN, consumer.getToken(), OAuth.OAUTH_CALLBACK, callbackUrl); } }
public static String addQueryParameters(String url, Map<String, String> params) { String[] kvPairs = new String[params.size() * 2]; int idx = 0; for (String key : params.keySet()) { kvPairs[idx] = key; kvPairs[idx + 1] = params.get(key); idx += 2; } return addQueryParameters(url, kvPairs); }
@Deprecated public String redirectUrl(TokenPair tokenPair) { return oauth.signpost.OAuth.addQueryParameters(provider.getAuthorizationWebsiteUrl(), oauth.signpost.OAuth.OAUTH_TOKEN, tokenPair.token); }
/** * The URL where the user needs to be redirected to grant authorization to your application. * * @param token request token */ public String redirectUrl(String token) { return oauth.signpost.OAuth.addQueryParameters( provider.getAuthorizationWebsiteUrl(), oauth.signpost.OAuth.OAUTH_TOKEN, token ); }
/** * The URL where the user needs to be redirected to grant authorization to your application. * * @param token request token * @return the url */ public String redirectUrl(String token) { return oauth.signpost.OAuth.addQueryParameters( provider.getAuthorizationWebsiteUrl(), oauth.signpost.OAuth.OAUTH_TOKEN, token ); }
public String redirectUrl(String token) { return oauth.signpost.OAuth.addQueryParameters(provider.getAuthorizationWebsiteUrl(), oauth.signpost.OAuth.OAUTH_TOKEN, token); }
public synchronized String retrieveRequestToken(OAuthConsumer consumer, String callbackUrl, String... customOAuthParams) throws OAuthMessageSignerException, OAuthNotAuthorizedException, OAuthExpectationFailedException, OAuthCommunicationException { // invalidate current credentials, if any consumer.setTokenWithSecret(null, null); // 1.0a expects the callback to be sent while getting the request token. // 1.0 service providers would simply ignore this parameter. HttpParameters params = new HttpParameters(); params.putAll(customOAuthParams, true); params.put(OAuth.OAUTH_CALLBACK, callbackUrl, true); retrieveToken(consumer, requestTokenEndpointUrl, params); String callbackConfirmed = responseParameters.getFirst(OAuth.OAUTH_CALLBACK_CONFIRMED); responseParameters.remove(OAuth.OAUTH_CALLBACK_CONFIRMED); isOAuth10a = Boolean.TRUE.toString().equals(callbackConfirmed); // 1.0 service providers expect the callback as part of the auth URL, // Do not send when 1.0a. if (isOAuth10a) { return OAuth.addQueryParameters(authorizationWebsiteUrl, OAuth.OAUTH_TOKEN, consumer.getToken()); } else { return OAuth.addQueryParameters(authorizationWebsiteUrl, OAuth.OAUTH_TOKEN, consumer.getToken(), OAuth.OAUTH_CALLBACK, callbackUrl); } }