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

48
LINES

< > BotCompany Repo | #1013811 // googleVerifyUserToken

JavaX fragment (include)

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  
//lib 1013820 // appengine api sdk
8  
9  
import com.google.api.client.googleapis.auth.oauth2.GoogleIdToken;
10  
import com.google.api.client.googleapis.auth.oauth2.GoogleIdToken.Payload;
11  
import com.google.api.client.googleapis.auth.oauth2.GoogleIdTokenVerifier;
12  
import com.google.api.client.json.jackson2.JacksonFactory;
13  
//import com.google.api.client.extensions.appengine.http.UrlFetchTransport;
14  
import com.google.api.client.http.javanet.NetHttpTransport;
15  
16  
static bool googleVerifyUserToken(S clientID, S token) ctex {
17  
  //UrlFetchTransport.getDefaultInstance();
18  
  new NetHttpTransport transport;
19  
  
20  
  GoogleIdTokenVerifier verifier = new GoogleIdTokenVerifier.Builder(transport, new JacksonFactory)
21  
    // Specify the CLIENT_ID of the app that accesses the backend:
22  
    .setAudience(Collections.singletonList(clientID))
23  
    .build();
24  
  
25  
  GoogleIdToken idToken = verifier.verify(token);
26  
  if (idToken != null) {
27  
    Payload payload = idToken.getPayload();
28  
  
29  
    // Print user identifier
30  
    String userId = payload.getSubject();
31  
    print("User ID: " + userId);
32  
  
33  
    // Get profile information from payload
34  
    String email = payload.getEmail();
35  
    boolean emailVerified = Boolean.valueOf(payload.getEmailVerified());
36  
    String name = (String) payload.get("name");
37  
    String pictureUrl = (String) payload.get("picture");
38  
    String locale = (String) payload.get("locale");
39  
    String familyName = (String) payload.get("family_name");
40  
    String givenName = (String) payload.get("given_name");
41  
  
42  
    print("Name: " + name);
43  
    true;
44  
  } else {
45  
    print("Invalid ID token.");
46  
    false;
47  
  }
48  
}

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1013811
Snippet name: googleVerifyUserToken
Eternal ID of this version: #1013811/16
Text MD5: c2b80caf9768a427ebbcdaab8b8d163e
Author: stefan
Category: javax / web
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-03-02 17:38:58
Source code size: 1839 bytes / 48 lines
Pitched / IR pitched: No / No
Views / Downloads: 443 / 436
Version history: 15 change(s)
Referenced in: [show references]