Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

32
LINES

< > BotCompany Repo | #1013821 // googleVerifyUserToken2

JavaX fragment (include) [tags: use-pretranspiled]

Uses 1658K of libraries. Click here for Pure Java version (2499L/16K).

1  
lib 1013814 // google http client
2  
lib 1013815 // google api client
3  
lib 1013816 // google oauth client
4  
lib 1013817 // jackson
5  
lib 1013818 // google jackson2
6  
lib 1013819 // google http client appengine
7  
8  
import com.google.api.client.googleapis.auth.oauth2.GoogleIdToken;
9  
import com.google.api.client.googleapis.auth.oauth2.GoogleIdToken.Payload;
10  
import com.google.api.client.googleapis.auth.oauth2.GoogleIdTokenVerifier;
11  
import com.google.api.client.json.jackson2.JacksonFactory;
12  
import com.google.api.client.http.javanet.NetHttpTransport;
13  
14  
static Payload googleVerifyUserToken2(S clientID, S token) ctex {
15  
  print("Google verify started.");
16  
  
17  
  new NetHttpTransport transport;
18  
  
19  
  GoogleIdTokenVerifier verifier = new GoogleIdTokenVerifier.Builder(transport, new JacksonFactory)
20  
    .setAudience(Collections.singletonList(clientID))
21  
    .build();
22  
  
23  
  GoogleIdToken idToken = verifier.verify(token);
24  
  if (idToken != null) {
25  
    Payload payload = idToken.getPayload();
26  
    print("Google verify confirmed: " + payload.getEmail());
27  
    ret payload;
28  
  }
29  
  
30  
  print("Google verify failed");
31  
  null;
32  
}

Author comment

Began life as a copy of #1013811

download  show line numbers  debug dex  old transpilations   

Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv

No comments. add comment

Snippet ID: #1013821
Snippet name: googleVerifyUserToken2
Eternal ID of this version: #1013821/3
Text MD5: fb1dc58a4ddeb52b7f2fc903bde8d15e
Transpilation MD5: 06ff259e2c2ed3b3b91d034b7d93cd18
Author: stefan
Category: javax / web
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-07-14 13:13:11
Source code size: 1127 bytes / 32 lines
Pitched / IR pitched: No / No
Views / Downloads: 381 / 476
Version history: 2 change(s)
Referenced in: [show references]