From 99d00a4ec0047d3eadbc0d11e14468283130f89e Mon Sep 17 00:00:00 2001 From: Shi Jinghai Date: Sun, 10 Apr 2016 05:59:25 +0000 Subject: [PATCH] OFBIZ-6755 Update the passport component to use httpclient/core-4.4.1 instead of commons-httpclient-3.1 1. Changed Applications to OAuth applications in README Github section. 2. Corrected the uri build to make the Github and LinkedIn OAuth login work. git-svn-id: https://svn.apache.org/repos/asf/ofbiz/trunk/specialpurpose@1738407 13f79535-47bb-0310-9956-ffa450edef68 --- passport/README | 2 +- passport/src/org/ofbiz/passport/event/GitHubEvents.java | 7 ++++--- passport/src/org/ofbiz/passport/event/LinkedInEvents.java | 5 +++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/passport/README b/passport/README index 064d59de6..83abb17a0 100644 --- a/passport/README +++ b/passport/README @@ -16,7 +16,7 @@ Here are the steps for a quick start in OFBiz trunk: 2. Login GitHub. -3. Visit Settings->Applications->Developer applications, click "Register new application" button. +3. Visit Settings->OAuth applications->Developer applications, click "Register new application" button. 4. In "Register a new OAuth application", fill in your OFBiz website information. Here the Authorization callback URL: https://YourWebSiteOrInternetIp:8443/ecomseo/githubResponse diff --git a/passport/src/org/ofbiz/passport/event/GitHubEvents.java b/passport/src/org/ofbiz/passport/event/GitHubEvents.java index 4ce510999..a6dc25644 100644 --- a/passport/src/org/ofbiz/passport/event/GitHubEvents.java +++ b/passport/src/org/ofbiz/passport/event/GitHubEvents.java @@ -171,12 +171,13 @@ public class GitHubEvents { try { URI uri = new URIBuilder() - .setHost(TokenEndpoint) + .setScheme(TokenEndpoint.substring(0, TokenEndpoint.indexOf(":"))) + .setHost(TokenEndpoint.substring(TokenEndpoint.indexOf(":") + 3)) .setPath(TokenServiceUri) .setParameter("client_id", clientId) .setParameter("client_secret", secret) .setParameter("code", authorizationCode) - .setParameter("redirect_uri", URLEncoder.encode(returnURI, "UTF-8")) + .setParameter("redirect_uri", returnURI) .build(); HttpPost postMethod = new HttpPost(uri); CloseableHttpClient jsonClient = HttpClients.custom().build(); @@ -188,7 +189,7 @@ public class GitHubEvents { // Debug.logInfo("GitHub get access token response code: " + postResponse.getStatusLine().getStatusCode(), module); // Debug.logInfo("GitHub get access token response content: " + responseString, module); if (postResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { - // Debug.logInfo("Json Response from GitHub: " + responseString, module); + Debug.logInfo("Json Response from GitHub: " + responseString, module); JSON jsonObject = JSON.from(responseString); JSONToMap jsonMap = new JSONToMap(); Map userMap = jsonMap.convert(jsonObject); diff --git a/passport/src/org/ofbiz/passport/event/LinkedInEvents.java b/passport/src/org/ofbiz/passport/event/LinkedInEvents.java index 96db013a7..eb9a71ee9 100644 --- a/passport/src/org/ofbiz/passport/event/LinkedInEvents.java +++ b/passport/src/org/ofbiz/passport/event/LinkedInEvents.java @@ -171,13 +171,14 @@ public class LinkedInEvents { try { URI uri = new URIBuilder() - .setHost(TokenEndpoint) + .setScheme(TokenEndpoint.substring(0, TokenEndpoint.indexOf(":"))) + .setHost(TokenEndpoint.substring(TokenEndpoint.indexOf(":") + 3)) .setPath(TokenServiceUri) .setParameter("client_id", clientId) .setParameter("client_secret", secret) .setParameter("grant_type", "authorization_code") .setParameter("code", authorizationCode) - .setParameter("redirect_uri", URLEncoder.encode(returnURI, "UTF-8")) + .setParameter("redirect_uri", returnURI) .build(); HttpPost postMethod = new HttpPost(uri); CloseableHttpClient jsonClient = HttpClients.custom().build();