Return-Path: X-Original-To: apmail-camel-commits-archive@www.apache.org Delivered-To: apmail-camel-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 7884B18D1F for ; Fri, 18 Sep 2015 07:43:08 +0000 (UTC) Received: (qmail 2304 invoked by uid 500); 18 Sep 2015 07:43:08 -0000 Delivered-To: apmail-camel-commits-archive@camel.apache.org Received: (qmail 2246 invoked by uid 500); 18 Sep 2015 07:43:08 -0000 Mailing-List: contact commits-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@camel.apache.org Delivered-To: mailing list commits@camel.apache.org Received: (qmail 2237 invoked by uid 99); 18 Sep 2015 07:43:08 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 18 Sep 2015 07:43:08 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 310D8E03A7; Fri, 18 Sep 2015 07:43:08 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: dhirajsb@apache.org To: commits@camel.apache.org Message-Id: <8e8804706e6f4dfe9242bd657a5b64b9@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: camel git commit: CAMEL-8898: Added error handling for new LinkedIn OAuth behavior, also added w_share scope Date: Fri, 18 Sep 2015 07:43:08 +0000 (UTC) Repository: camel Updated Branches: refs/heads/master 30c735106 -> df556c4a5 CAMEL-8898: Added error handling for new LinkedIn OAuth behavior, also added w_share scope Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/df556c4a Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/df556c4a Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/df556c4a Branch: refs/heads/master Commit: df556c4a58b9d04aad64a8ce761bbfef8b75da3a Parents: 30c7351 Author: Dhiraj Bokde Authored: Fri Sep 18 00:42:58 2015 -0700 Committer: Dhiraj Bokde Committed: Fri Sep 18 00:42:58 2015 -0700 ---------------------------------------------------------------------- .../api/LinkedInOAuthRequestFilter.java | 27 +++++++++++++++----- .../component/linkedin/api/OAuthScope.java | 4 ++- 2 files changed, 24 insertions(+), 7 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/df556c4a/components/camel-linkedin/camel-linkedin-api/src/main/java/org/apache/camel/component/linkedin/api/LinkedInOAuthRequestFilter.java ---------------------------------------------------------------------- diff --git a/components/camel-linkedin/camel-linkedin-api/src/main/java/org/apache/camel/component/linkedin/api/LinkedInOAuthRequestFilter.java b/components/camel-linkedin/camel-linkedin-api/src/main/java/org/apache/camel/component/linkedin/api/LinkedInOAuthRequestFilter.java index d625bc5..7c5def9 100644 --- a/components/camel-linkedin/camel-linkedin-api/src/main/java/org/apache/camel/component/linkedin/api/LinkedInOAuthRequestFilter.java +++ b/components/camel-linkedin/camel-linkedin-api/src/main/java/org/apache/camel/component/linkedin/api/LinkedInOAuthRequestFilter.java @@ -19,6 +19,7 @@ package org.apache.camel.component.linkedin.api; import java.io.IOException; import java.net.URI; import java.net.URL; +import java.net.URLDecoder; import java.net.URLEncoder; import java.security.SecureRandom; import java.util.HashMap; @@ -131,8 +132,8 @@ public final class LinkedInOAuthRequestFilter implements ClientRequestFilter { @SuppressWarnings("deprecation") private String getRefreshToken() { - // authorize application on user's behalf - webClient.getOptions().setRedirectEnabled(true); + // disable redirect to avoid loading error redirect URL + webClient.getOptions().setRedirectEnabled(false); try { final String csrfId = String.valueOf(new SecureRandom().nextLong()); @@ -157,7 +158,24 @@ public final class LinkedInOAuthRequestFilter implements ClientRequestFilter { url = String.format(AUTHORIZATION_URL_WITH_SCOPE, oAuthParams.getClientId(), csrfId, builder.toString(), encodedRedirectUri); } - final HtmlPage authPage = webClient.getPage(url); + HtmlPage authPage; + try { + authPage = webClient.getPage(url); + } catch (FailingHttpStatusCodeException e) { + // only handle errors returned with redirects + if (e.getStatusCode() == HttpStatus.SC_MOVED_TEMPORARILY) { + final URL location = new URL(e.getResponse().getResponseHeaderValue(HttpHeaders.LOCATION)); + final String locationQuery = location.getQuery(); + if (locationQuery != null && locationQuery.contains("error=")) { + throw new IOException(URLDecoder.decode(locationQuery).replaceAll("&", ", ")); + } else { + // follow the redirect to login form + authPage = webClient.getPage(location); + } + } else { + throw e; + } + } // look for
final HtmlDivision div = authPage.getFirstByXPath("//div[@role='alert']"); @@ -173,9 +191,6 @@ public final class LinkedInOAuthRequestFilter implements ClientRequestFilter { password.setText(oAuthParams.getUserPassword()); final HtmlSubmitInput submitInput = loginForm.getInputByName("authorize"); - // disable redirect to avoid loading redirect URL - webClient.getOptions().setRedirectEnabled(false); - // validate CSRF and get authorization code String redirectQuery; try { http://git-wip-us.apache.org/repos/asf/camel/blob/df556c4a/components/camel-linkedin/camel-linkedin-api/src/main/java/org/apache/camel/component/linkedin/api/OAuthScope.java ---------------------------------------------------------------------- diff --git a/components/camel-linkedin/camel-linkedin-api/src/main/java/org/apache/camel/component/linkedin/api/OAuthScope.java b/components/camel-linkedin/camel-linkedin-api/src/main/java/org/apache/camel/component/linkedin/api/OAuthScope.java index aadf353..3549061 100644 --- a/components/camel-linkedin/camel-linkedin-api/src/main/java/org/apache/camel/component/linkedin/api/OAuthScope.java +++ b/components/camel-linkedin/camel-linkedin-api/src/main/java/org/apache/camel/component/linkedin/api/OAuthScope.java @@ -26,10 +26,12 @@ public enum OAuthScope { R_EMAILADDRESS("r_emailaddress"), R_NETWORK("r_network"), R_CONTACTINFO("r_contactinfo"), + @Deprecated // use W_SHARE instead RW_NUS("rw_nus"), RW_COMPANY_ADMIN("rw_company_admin"), RW_GROUPS("rw_groups"), - W_MESSAGES("w_messages"); + W_MESSAGES("w_messages"), + W_SHARE("w_share"); private final String value;