158 lines
5.0 KiB
Java
158 lines
5.0 KiB
Java
//package rest;
|
|
//
|
|
//import java.io.BufferedReader;
|
|
//import java.io.IOException;
|
|
//import java.io.InputStreamReader;
|
|
//import java.io.Serializable;
|
|
//import java.io.UnsupportedEncodingException;
|
|
//import java.net.HttpURLConnection;
|
|
//import java.net.URL;
|
|
//import java.security.GeneralSecurityException;
|
|
//import java.util.Arrays;
|
|
//import java.util.Base64;
|
|
//import java.util.Collections;
|
|
//import java.util.List;
|
|
//import java.util.UUID;
|
|
//
|
|
//import org.springframework.http.HttpStatus;
|
|
//import org.springframework.http.ResponseEntity;
|
|
//import org.springframework.web.bind.annotation.CrossOrigin;
|
|
//import org.springframework.web.bind.annotation.RequestBody;
|
|
//import org.springframework.web.bind.annotation.RequestMapping;
|
|
//import org.springframework.web.bind.annotation.RequestMethod;
|
|
//import org.springframework.web.bind.annotation.RequestParam;
|
|
//import org.springframework.web.bind.annotation.ResponseBody;
|
|
//import org.springframework.web.bind.annotation.RestController;
|
|
//
|
|
//import com.fasterxml.jackson.databind.ObjectMapper;
|
|
//
|
|
//import entities.DMP;
|
|
////import io.jsonwebtoken.Claims;
|
|
////import io.jsonwebtoken.ExpiredJwtException;
|
|
////import io.jsonwebtoken.Jws;
|
|
////import io.jsonwebtoken.Jwts;
|
|
////import io.jsonwebtoken.MalformedJwtException;
|
|
////import io.jsonwebtoken.SignatureException;
|
|
////import io.jsonwebtoken.UnsupportedJwtException;
|
|
////import security.GoogleKey;
|
|
////import security.GoogleKeys;
|
|
//
|
|
//
|
|
//import com.google.api.client.googleapis.auth.oauth2.GoogleIdToken;
|
|
//import com.google.api.client.googleapis.auth.oauth2.GoogleIdToken.Payload;
|
|
//import com.google.api.client.googleapis.auth.oauth2.GoogleIdTokenVerifier;
|
|
//import com.google.api.client.http.HttpTransport;
|
|
//import com.google.api.client.http.apache.ApacheHttpTransport;
|
|
//import com.google.api.client.http.javanet.NetHttpTransport;
|
|
//import com.google.api.client.json.JsonFactory;
|
|
//import com.google.api.client.json.jackson2.JacksonFactory;
|
|
//
|
|
//
|
|
//
|
|
//@RestController
|
|
//@CrossOrigin
|
|
//public class TokenManager {
|
|
//
|
|
//
|
|
//// public static final String GOOGLE_KEYS_URL = "https://www.googleapis.com/oauth2/v3/certs";
|
|
//// public static GoogleKeys GOOGLE_KEYS;
|
|
//
|
|
// private static final JacksonFactory jacksonFactory = new JacksonFactory();
|
|
// private static final HttpTransport transport = new NetHttpTransport();
|
|
//
|
|
// private static GoogleIdTokenVerifier verifier;
|
|
//
|
|
// private static final List<String> clientIDs = Arrays.asList("1010962018903-glegmqudqtl1lub0150vacopbu06lgsg.apps.googleusercontent.com");
|
|
//
|
|
//
|
|
//
|
|
//
|
|
//
|
|
//
|
|
// static {
|
|
// verifier = new GoogleIdTokenVerifier.Builder(transport, jacksonFactory)
|
|
// .setAudience(clientIDs)
|
|
// // Or, if multiple clients access the backend:
|
|
// //.setAudience(Arrays.asList(CLIENT_ID_1, CLIENT_ID_2, CLIENT_ID_3))
|
|
// .build();
|
|
// }
|
|
//
|
|
//
|
|
//
|
|
//
|
|
// @RequestMapping(method = RequestMethod.POST, value = { "/login" }, produces="text/plain")
|
|
// public @ResponseBody ResponseEntity<Object> login(
|
|
// @RequestParam("token") String token
|
|
// ){
|
|
//
|
|
// System.out.println(token);
|
|
//
|
|
// // 1. CHECK IF IT'S A VALID TOKEN
|
|
//
|
|
// GoogleIdToken idToken = null;
|
|
// try {
|
|
// idToken = verifier.verify(token);
|
|
// }
|
|
// catch(GeneralSecurityException ex) {
|
|
// return ResponseEntity.status(HttpStatus.FORBIDDEN).body("{'reason': 'Token is not valid'}");
|
|
// }
|
|
// catch(IOException ex) {
|
|
// return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{'reason': 'Could not verify token'}");
|
|
// }
|
|
//
|
|
//
|
|
// if (idToken != null) {
|
|
// Payload payload = idToken.getPayload();
|
|
//
|
|
// System.out.println("=============================");
|
|
// // Print user identifier
|
|
// String userId = payload.getSubject();
|
|
// System.out.println("User ID: " + userId);
|
|
//
|
|
// // Get profile information from payload
|
|
// String email = payload.getEmail();
|
|
// boolean emailVerified = Boolean.valueOf(payload.getEmailVerified());
|
|
// String name = (String) payload.get("name");
|
|
// String pictureUrl = (String) payload.get("picture");
|
|
// String locale = (String) payload.get("locale");
|
|
// String familyName = (String) payload.get("family_name");
|
|
// String givenName = (String) payload.get("given_name");
|
|
//
|
|
// System.out.println(email);
|
|
// System.out.println(name);
|
|
// System.out.println(familyName);
|
|
// System.out.println(locale);
|
|
// System.out.println(givenName);
|
|
// System.out.println(emailVerified);
|
|
// System.out.println(pictureUrl);
|
|
//
|
|
//
|
|
// } else {
|
|
// System.out.println("Invalid ID token.");
|
|
// }
|
|
//
|
|
//
|
|
// // 2.1 IF SO, ADD USER ON THE DATABASE
|
|
//
|
|
// // 2.2 also handle it within the session (create a c\\.ustom session)
|
|
//
|
|
//
|
|
//
|
|
// return ResponseEntity.status(HttpStatus.OK).body("{'status': 'ok'}");
|
|
//
|
|
//// try {
|
|
//// List<UUID> allIDs = dMPDao.listAllIDs();
|
|
//// return ResponseEntity.status(HttpStatus.OK).body(new ObjectMapper().writeValueAsString(allIDs));
|
|
//// }
|
|
//// catch(Exception ex) {
|
|
//// return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: "+ex.getMessage());
|
|
//// }
|
|
//
|
|
//
|
|
// }
|
|
//
|
|
//
|
|
//
|
|
//}
|
|
//
|