aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/juick/server/api/ApiSocialLogin.java
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2020-02-27 14:00:13 +0300
committerGravatar Vitaly Takmazov2020-02-27 14:01:01 +0300
commit6d177fbb3e57409b223e835eabc79009a89a1031 (patch)
tree5144cf89e6095c8ec693a771dd284fc3cce11d6e /src/main/java/com/juick/server/api/ApiSocialLogin.java
parent8f3a101df251de5965ca28086974c2c10f60c6d9 (diff)
API: handle existing Google user flow
Diffstat (limited to 'src/main/java/com/juick/server/api/ApiSocialLogin.java')
-rw-r--r--src/main/java/com/juick/server/api/ApiSocialLogin.java25
1 files changed, 10 insertions, 15 deletions
diff --git a/src/main/java/com/juick/server/api/ApiSocialLogin.java b/src/main/java/com/juick/server/api/ApiSocialLogin.java
index 8ca7d6d8..6a6b4293 100644
--- a/src/main/java/com/juick/server/api/ApiSocialLogin.java
+++ b/src/main/java/com/juick/server/api/ApiSocialLogin.java
@@ -32,7 +32,7 @@ import com.google.api.client.http.HttpTransport;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.jackson2.JacksonFactory;
-import com.juick.model.Auth;
+import com.juick.model.AuthResponse;
import com.juick.model.facebook.User;
import com.juick.server.util.HttpBadRequestException;
import com.juick.service.CrosspostService;
@@ -40,20 +40,11 @@ import com.juick.service.EmailService;
import com.juick.service.UserService;
import com.juick.model.vk.UsersResponse;
import com.nimbusds.jose.JOSEException;
-import com.nimbusds.jose.JWSAlgorithm;
-import com.nimbusds.jose.jwk.source.JWKSource;
-import com.nimbusds.jose.jwk.source.RemoteJWKSet;
import com.nimbusds.jose.proc.BadJOSEException;
-import com.nimbusds.jose.proc.JWSKeySelector;
-import com.nimbusds.jose.proc.JWSVerificationKeySelector;
-import com.nimbusds.jose.proc.SecurityContext;
-import com.nimbusds.jwt.proc.ConfigurableJWTProcessor;
-import com.nimbusds.jwt.proc.DefaultJWTClaimsVerifier;
-import com.nimbusds.jwt.proc.DefaultJWTProcessor;
-import net.minidev.json.JSONObject;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
+import org.checkerframework.checker.units.qual.A;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
@@ -69,7 +60,6 @@ import org.springframework.web.util.UriComponentsBuilder;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
import java.io.IOException;
-import java.net.URL;
import java.security.GeneralSecurityException;
import java.text.ParseException;
import java.util.Collections;
@@ -120,6 +110,8 @@ public class ApiSocialLogin {
private EmailService emailService;
@Inject
private AppleClientSecretGenerator clientSecretGenerator;
+ @Inject
+ private Users users;
private final HttpTransport transport = new NetHttpTransport();
private final JsonFactory jsonFactory = new JacksonFactory();
@@ -254,17 +246,20 @@ public class ApiSocialLogin {
}
@ResponseBody
@PostMapping("/api/_google")
- public ResponseEntity<Auth> googleSignIn(@RequestParam(name = "idToken") String idTokenString)
+ public ResponseEntity<AuthResponse> googleSignIn(@RequestParam(name = "idToken") String idTokenString)
throws GeneralSecurityException, IOException {
logger.info("Token: {}", idTokenString);
logger.info("Client: {}", googleClientId);
GoogleIdToken idToken = verifier.verify(idTokenString);
if (idToken != null) {
String email = idToken.getPayload().getEmail();
- if (userService.getUserByEmail(email).isAnonymous()) {
+ com.juick.User visitor = userService.getUserByEmail(email);
+ if (visitor.isAnonymous()) {
String verificationCode = RandomStringUtils.randomAlphanumeric(8).toUpperCase();
emailService.addVerificationCode(null, email, verificationCode);
- return ResponseEntity.ok(new Auth(email, verificationCode));
+ return ResponseEntity.ok(new AuthResponse(null, email, verificationCode));
+ } else {
+ return ResponseEntity.ok(new AuthResponse(users.getMe(visitor), null, null));
}
}
return ResponseEntity.status(HttpStatus.FORBIDDEN).body(null);