aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2018-06-21 21:30:57 +0300
committerGravatar Vitaly Takmazov2018-06-21 21:30:57 +0300
commit85ff16fe77a45af9baac7581c2757b1ee59767d6 (patch)
tree931c38492c5fc516ad389ac6b4f2134a81889770
parent248c05840275516cbc5c99c8e5d87d007ca37284 (diff)
initial Facebook login
-rw-r--r--juick-common/src/main/java/com/juick/facebook/User.java (renamed from juick-www/src/main/java/com/juick/www/facebook/User.java)2
-rw-r--r--juick-common/src/main/java/com/juick/twitter/User.java (renamed from juick-www/src/main/java/com/juick/www/twitter/User.java)2
-rw-r--r--juick-common/src/main/java/com/juick/vk/Token.java (renamed from juick-www/src/main/java/com/juick/www/vk/Token.java)2
-rw-r--r--juick-common/src/main/java/com/juick/vk/User.java (renamed from juick-www/src/main/java/com/juick/www/vk/User.java)2
-rw-r--r--juick-common/src/main/java/com/juick/vk/UsersResponse.java (renamed from juick-www/src/main/java/com/juick/www/vk/UsersResponse.java)2
-rw-r--r--juick-server/build.gradle1
-rw-r--r--juick-server/src/main/java/com/juick/server/Utils.java (renamed from juick-www/src/main/java/com/juick/www/Utils.java)2
-rw-r--r--juick-server/src/main/java/com/juick/server/api/SocialLogin.java (renamed from juick-www/src/main/java/com/juick/www/controllers/SocialLogin.java)47
8 files changed, 23 insertions, 37 deletions
diff --git a/juick-www/src/main/java/com/juick/www/facebook/User.java b/juick-common/src/main/java/com/juick/facebook/User.java
index b56c4ee3..ebd427b4 100644
--- a/juick-www/src/main/java/com/juick/www/facebook/User.java
+++ b/juick-common/src/main/java/com/juick/facebook/User.java
@@ -15,7 +15,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-package com.juick.www.facebook;
+package com.juick.facebook;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
diff --git a/juick-www/src/main/java/com/juick/www/twitter/User.java b/juick-common/src/main/java/com/juick/twitter/User.java
index a92daa92..0b4b9c87 100644
--- a/juick-www/src/main/java/com/juick/www/twitter/User.java
+++ b/juick-common/src/main/java/com/juick/twitter/User.java
@@ -15,7 +15,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-package com.juick.www.twitter;
+package com.juick.twitter;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
diff --git a/juick-www/src/main/java/com/juick/www/vk/Token.java b/juick-common/src/main/java/com/juick/vk/Token.java
index bcc36639..979c572c 100644
--- a/juick-www/src/main/java/com/juick/www/vk/Token.java
+++ b/juick-common/src/main/java/com/juick/vk/Token.java
@@ -15,7 +15,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-package com.juick.www.vk;
+package com.juick.vk;
import com.fasterxml.jackson.annotation.JsonProperty;
diff --git a/juick-www/src/main/java/com/juick/www/vk/User.java b/juick-common/src/main/java/com/juick/vk/User.java
index 749631bb..00025497 100644
--- a/juick-www/src/main/java/com/juick/www/vk/User.java
+++ b/juick-common/src/main/java/com/juick/vk/User.java
@@ -15,7 +15,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-package com.juick.www.vk;
+package com.juick.vk;
import com.fasterxml.jackson.annotation.JsonProperty;
diff --git a/juick-www/src/main/java/com/juick/www/vk/UsersResponse.java b/juick-common/src/main/java/com/juick/vk/UsersResponse.java
index 6f645451..83092c99 100644
--- a/juick-www/src/main/java/com/juick/www/vk/UsersResponse.java
+++ b/juick-common/src/main/java/com/juick/vk/UsersResponse.java
@@ -15,7 +15,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-package com.juick.www.vk;
+package com.juick.vk;
import com.fasterxml.jackson.annotation.JsonProperty;
diff --git a/juick-server/build.gradle b/juick-server/build.gradle
index a4b8b940..d026c476 100644
--- a/juick-server/build.gradle
+++ b/juick-server/build.gradle
@@ -13,6 +13,7 @@ dependencies {
compile 'io.springfox:springfox-swagger-ui:2.9.0'
compile 'org.apache.commons:commons-email:1.5'
+ compile 'com.github.scribejava:scribejava-apis:5.5.0'
compile 'com.github.ooxi:serialized-php-parser:0.5.0'
compile 'com.github.pengrad:java-telegram-bot-api:3.6.0'
compile 'com.github.messenger4j:messenger4j:1.0.0'
diff --git a/juick-www/src/main/java/com/juick/www/Utils.java b/juick-server/src/main/java/com/juick/server/Utils.java
index 3b1932d0..853b79fc 100644
--- a/juick-www/src/main/java/com/juick/www/Utils.java
+++ b/juick-server/src/main/java/com/juick/server/Utils.java
@@ -14,7 +14,7 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-package com.juick.www;
+package com.juick.server;
import javax.servlet.http.HttpServletRequest;
import java.util.Optional;
diff --git a/juick-www/src/main/java/com/juick/www/controllers/SocialLogin.java b/juick-server/src/main/java/com/juick/server/api/SocialLogin.java
index 7be83748..9ca0c6be 100644
--- a/juick-www/src/main/java/com/juick/www/controllers/SocialLogin.java
+++ b/juick-server/src/main/java/com/juick/server/api/SocialLogin.java
@@ -14,48 +14,36 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-package com.juick.www.controllers;
+package com.juick.server.api;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.scribejava.apis.FacebookApi;
-import com.github.scribejava.apis.TwitterApi;
-import com.github.scribejava.apis.VkontakteApi;
import com.github.scribejava.core.builder.ServiceBuilder;
-import com.github.scribejava.core.model.*;
-import com.github.scribejava.core.oauth.OAuth10aService;
+import com.github.scribejava.core.model.OAuth2AccessToken;
+import com.github.scribejava.core.model.OAuthRequest;
+import com.github.scribejava.core.model.Verb;
import com.github.scribejava.core.oauth.OAuth20Service;
+import com.juick.facebook.User;
import com.juick.server.util.HttpBadRequestException;
-import com.juick.server.util.UserUtils;
import com.juick.service.CrosspostService;
import com.juick.service.EmailService;
import com.juick.service.TelegramService;
import com.juick.service.UserService;
-import com.juick.www.Utils;
-import com.juick.www.facebook.User;
-import com.juick.www.vk.UsersResponse;
-import org.apache.commons.codec.digest.DigestUtils;
-import org.apache.commons.codec.digest.HmacAlgorithms;
-import org.apache.commons.codec.digest.HmacUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
-import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.util.UriComponentsBuilder;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
-import javax.servlet.http.Cookie;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
-import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ExecutionException;
-import java.util.stream.Collectors;
/**
*
@@ -105,10 +93,8 @@ public class SocialLogin {
}
@GetMapping("/_fblogin")
- protected String doFacebookLogin(HttpServletRequest request,
- @RequestParam(required = false) String code,
- @RequestParam(required = false) String state,
- HttpServletResponse response) throws IOException, ExecutionException, InterruptedException {
+ protected String doFacebookLogin(@RequestParam(required = false) String code,
+ @RequestParam(required = false) String state) throws IOException, ExecutionException, InterruptedException {
if (StringUtils.isBlank(code)) {
String fbstate = UUID.randomUUID().toString();
crosspostService.addFacebookState(fbstate);
@@ -153,10 +139,9 @@ public class SocialLogin {
logger.error("error updating facebook user, id: {}, token: {}", fbID, token.getAccessToken());
throw new HttpBadRequestException();
}
- Cookie c = new Cookie("hash", userService.getHashByUID(uid));
- c.setMaxAge(50 * 24 * 60 * 60);
- response.addCookie(c);
- return "redirect:/";
+ UriComponentsBuilder uriComponentsBuilder = UriComponentsBuilder.fromUriString(state);
+ uriComponentsBuilder.queryParam("hash", userService.getHashByUID(uid));
+ return "redirect:" + uriComponentsBuilder.build().toUriString();
} else if (fb.getVerified()) {
if (!crosspostService.createFacebookUser(fbID, state, token.getAccessToken(), fb.getName(), fb.getLink())) {
if (StringUtils.isNotEmpty(fb.getEmail())) {
@@ -174,7 +159,7 @@ public class SocialLogin {
logger.error("Facebook account is not verified, id: {}", fbID);
throw new HttpBadRequestException();
}
- }
+ }/*
@GetMapping("/_twitter")
protected void doTwitterLogin(HttpServletRequest request, HttpServletResponse response)
throws IOException, ExecutionException, InterruptedException {
@@ -212,8 +197,8 @@ public class SocialLogin {
OAuth1AccessToken accessToken = oAuthService.getAccessToken(requestToken, verifier);
OAuthRequest oAuthRequest = new OAuthRequest(Verb.GET, TWITTER_VERIFY_URL);
oAuthService.signRequest(accessToken, oAuthRequest);
- com.juick.www.twitter.User twitterUser = jsonMapper.readValue(oAuthService.execute(oAuthRequest).getBody(),
- com.juick.www.twitter.User.class);
+ com.juick.twitter.User twitterUser = jsonMapper.readValue(oAuthService.execute(oAuthRequest).getBody(),
+ com.juick.twitter.User.class);
if (userService.linkTwitterAccount(user, accessToken.getToken(), accessToken.getTokenSecret(),
twitterUser.getScreenName())) {
response.setStatus(HttpServletResponse.SC_FOUND);
@@ -261,7 +246,7 @@ public class SocialLogin {
vkService.signRequest(token, meRequest);
String graph = vkService.execute(meRequest).getBody();
- com.juick.www.vk.User jsonUser = jsonMapper.readValue(graph, UsersResponse.class).getUsers().get(0);
+ com.juick.vk.User jsonUser = jsonMapper.readValue(graph, UsersResponse.class).getUsers().get(0);
String vkName = jsonUser.getFirstName() + " " + jsonUser.getLastName();
String vkLink = jsonUser.getScreenName();
@@ -316,5 +301,5 @@ public class SocialLogin {
logger.warn("invalid tg hash {} for {}", resultString, hash);
}
throw new HttpBadRequestException();
- }
+ }*/
}