11package com .objectcomputing .checkins .services .request_notifications ;
22
33
4+ import com .google .api .client .googleapis .auth .oauth2 .GoogleIdToken ;
5+ import com .google .api .client .googleapis .auth .oauth2 .GoogleIdTokenVerifier ;
6+ import com .google .api .client .http .javanet .NetHttpTransport ;
7+ import com .google .api .client .json .gson .GsonFactory ;
48import io .micronaut .http .HttpResponse ;
59import io .micronaut .http .annotation .Controller ;
610import io .micronaut .http .annotation .Get ;
11+ import io .micronaut .http .annotation .Header ;
712import io .micronaut .scheduling .TaskExecutors ;
813import io .netty .channel .EventLoopGroup ;
914import jakarta .annotation .security .PermitAll ;
10-
1115import jakarta .inject .Named ;
1216import reactor .core .publisher .Mono ;
1317import reactor .core .scheduler .Schedulers ;
1418
19+ import java .io .IOException ;
20+ import java .security .GeneralSecurityException ;
21+ import java .util .Collections ;
1522import java .util .concurrent .ExecutorService ;
1623
1724@ Controller ("/services/feedback/daily-request-check" )
@@ -20,6 +27,10 @@ public class CheckServicesController {
2027 private final CheckServices checkServices ;
2128 private final EventLoopGroup eventLoopGroup ;
2229 private final ExecutorService ioExecutorService ;
30+ private final GoogleIdTokenVerifier verifier =
31+ new GoogleIdTokenVerifier .Builder (new NetHttpTransport (), new GsonFactory ())
32+ .setAudience (Collections .singletonList ("https://checkins.objectcomputing.com/services/feedback/daily-request-check" ))
33+ .build ();
2334
2435 public CheckServicesController (CheckServices checkServices , EventLoopGroup eventLoopGroup ,
2536 @ Named (TaskExecutors .IO ) ExecutorService ioExecutorService ) {
@@ -29,7 +40,37 @@ public CheckServicesController(CheckServices checkServices, EventLoopGroup event
2940 }
3041
3142 @ Get
32- public Mono <? extends HttpResponse <?>> GetTodaysRequests () {
43+ public Mono <? extends HttpResponse <?>> GetTodaysRequests (@ Header ("Authorization" ) String authorizationHeader ) {
44+ System .out .println ("!!!!!!-" +authorizationHeader );
45+ String authorization = authorizationHeader .split (" " )[1 ];
46+ GoogleIdToken idToken = null ;
47+ try {
48+ idToken = verifier .verify (authorization );
49+ GoogleIdToken .Payload payload = idToken .getPayload ();
50+
51+ // Print user identifier
52+ String userId = payload .getSubject ();
53+ System .out .println ("User ID: " + userId );
54+
55+ // Get profile information from payload
56+ String email = payload .getEmail ();
57+ System .out .println ("Email:" + email );
58+ String hostedDomain = payload .getHostedDomain ();
59+ System .out .println ("Hosted Domain" + hostedDomain );
60+ String prettyString = payload .toPrettyString ();
61+ System .out .println (prettyString );
62+ boolean emailVerified = payload .getEmailVerified ();
63+ System .out .println ("emailVerified:" + emailVerified );
64+ // String name = (String) payload.get("name");
65+ // String pictureUrl = (String) payload.get("picture");
66+ // String locale = (String) payload.get("locale");
67+ // String familyName = (String) payload.get("family_name");
68+ // String givenName = (String) payload.get("given_name");
69+ } catch (GeneralSecurityException | IOException e ) {
70+ throw new RuntimeException (e );
71+ }
72+
73+ GoogleIdToken .Payload payload = idToken .getPayload ();
3374 return Mono .fromCallable (checkServices ::GetTodaysRequests )
3475 .publishOn (Schedulers .fromExecutor (eventLoopGroup ))
3576 .map (success -> (HttpResponse <?>) HttpResponse .ok ())
0 commit comments