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

48
LINES

< > BotCompany Repo | #1013811 // googleVerifyUserToken

JavaX fragment (include)

lib 1013814 // google http client
lib 1013815 // google api client
lib 1013816 // google oauth client
lib 1013817 // jackson
lib 1013818 // google jackson2
lib 1013819 // google http client appengine
//lib 1013820 // appengine api sdk

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.json.jackson2.JacksonFactory;
//import com.google.api.client.extensions.appengine.http.UrlFetchTransport;
import com.google.api.client.http.javanet.NetHttpTransport;

static bool googleVerifyUserToken(S clientID, S token) ctex {
  //UrlFetchTransport.getDefaultInstance();
  new NetHttpTransport transport;
  
  GoogleIdTokenVerifier verifier = new GoogleIdTokenVerifier.Builder(transport, new JacksonFactory)
    // Specify the CLIENT_ID of the app that accesses the backend:
    .setAudience(Collections.singletonList(clientID))
    .build();
  
  GoogleIdToken idToken = verifier.verify(token);
  if (idToken != null) {
    Payload payload = idToken.getPayload();
  
    // Print user identifier
    String userId = payload.getSubject();
    print("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");
  
    print("Name: " + name);
    true;
  } else {
    print("Invalid ID token.");
    false;
  }
}

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: 442 / 435
Version history: 15 change(s)
Referenced in: [show references]