List of usage examples for com.google.api.client.googleapis.auth.oauth2 GoogleIdTokenVerifier GoogleIdTokenVerifier
public GoogleIdTokenVerifier(HttpTransport transport, JsonFactory jsonFactory)
From source file:co.uk.gauntface.devicelab.appengine.utils.GPlusTokenInfo.java
License:Open Source License
public static String getUserId(String token) { try {/* www. j ava 2 s .co m*/ JsonFactory jsonFactory = new JacksonFactory(); GoogleIdToken idToken = GoogleIdToken.parse(jsonFactory, token); if (token == null) { return null; } // Verify valid token, signed by google.com, intended for 3P GoogleIdTokenVerifier verifier = new GoogleIdTokenVerifier(new NetHttpTransport(), new JacksonFactory()); if (verifier.verify(idToken)) { Payload payload = idToken.getPayload(); return payload.getSubject(); } } catch (GeneralSecurityException e) { } catch (IOException e) { } return null; }
From source file:com.google.plus.samples.haikuplus.Authenticate.java
License:Open Source License
Authenticate(ExecutorService executor) {
this(new GoogleIdTokenVerifier(HaikuPlus.TRANSPORT, HaikuPlus.JSON_FACTORY), new GoogleIdTokenRepository(),
executor);
}
From source file:com.google.plus.samples.verifytoken.Checker.java
License:Open Source License
public Checker(String[] clientIDs, String audience) { mClientIDs = Arrays.asList(clientIDs); mAudience = audience;/*from ww w . j ava2s .co m*/ NetHttpTransport transport = new NetHttpTransport(); mJFactory = new JacksonFactory(); mVerifier = new GoogleIdTokenVerifier(transport, mJFactory); }
From source file:com.predic8.membrane.core.interceptor.oauth2.GoogleAuthorizationService.java
License:Apache License
public void init(Router router) { httpClient = httpClientConfiguration == null ? router.getResolverMap().getHTTPSchemaResolver().getHttpClient() : new HttpClient(httpClientConfiguration); factory = new JacksonFactory(); verifier = new GoogleIdTokenVerifier(new ApacheHttpTransport(), factory); uriFactory = router.getUriFactory(); }
From source file:com.rse.middleware.GoogleTokenVerifier.java
public Payload verify(String token) { try {/* w w w . j a v a2 s. c o m*/ String CLIENT_ID = this.CLIENT_ID; NetHttpTransport transport = new NetHttpTransport(); List mClientIDs = Arrays.asList(CLIENT_ID); JsonFactory jsonFactory = new GsonFactory(); GoogleIdTokenVerifier verifier; String mProblem = "Verification failed. (Time-out?)"; String mAudience = this.CLIENT_ID; verifier = new GoogleIdTokenVerifier(transport, jsonFactory); Payload payload = null; GoogleIdToken idToken = GoogleIdToken.parse(jsonFactory, token); if (verifier.verify(idToken)) { GoogleIdToken.Payload tempPayload = idToken.getPayload(); System.out.println(tempPayload.getAudience()); System.out.println(tempPayload.getIssuee()); System.out.println(tempPayload.getIssuer()); System.out.println(tempPayload.get("email")); if (!tempPayload.getAudience().equals(mAudience)) { mProblem = "Audience mismatch"; } else if (!mClientIDs.contains(tempPayload.getIssuee())) { mProblem = "Client ID mismatch"; } else { payload = tempPayload; } } else { System.out.println("Invalid ID token."); } return payload; } catch (GeneralSecurityException e) { System.out.println("Security issue: " + e.getLocalizedMessage()); } catch (IOException e) { System.out.println("Network problem: " + e.getLocalizedMessage()); } catch (IllegalArgumentException e) { System.out.println("Token Problem: " + e.getLocalizedMessage()); } catch (Exception e) { System.out.println("Exception: " + e.getLocalizedMessage()); } return null; }
From source file:function.IdTokenVerifierAndParser.java
public static GoogleIdToken.Payload getPayload(String tokenString) throws Exception { JacksonFactory jacksonFactory = new JacksonFactory(); GoogleIdTokenVerifier googleIdTokenVerifier = new GoogleIdTokenVerifier(new NetHttpTransport(), jacksonFactory);//from ww w . ja v a 2 s . c om GoogleIdToken token = GoogleIdToken.parse(jacksonFactory, tokenString); if (googleIdTokenVerifier.verify(token)) { GoogleIdToken.Payload payload = token.getPayload(); if (!GOOGLE_CLIENT_ID.equals(payload.getAudience())) { throw new IllegalArgumentException("Audience mismatch"); } else if (!GOOGLE_CLIENT_ID.equals(payload.getAuthorizedParty())) { throw new IllegalArgumentException("Client ID mismatch"); } return payload; } else { throw new IllegalArgumentException("id token cannot be verified"); } }
From source file:org.openhmis.util.Authentication.java
License:Mozilla Public License
public static String resolveIdentity(String id_token) { String externalId;/* ww w .j ava 2 s . c om*/ try { // Verify that the token is a legitimate google token GoogleIdToken token = GoogleIdToken.parse(JSON_FACTORY, id_token); GoogleIdTokenVerifier verifier = new GoogleIdTokenVerifier(TRANSPORT, JSON_FACTORY); verifier.verify(token); // If we get here then this is a valid google item externalId = token.getPayload().getEmail(); } catch (IOException e) { log.debug("IOException authenticating with Google: " + e.toString()); externalId = null; } catch (GeneralSecurityException e) { log.debug("GeneralSecurityException authenticating with Google: " + e.toString()); externalId = null; } catch (IllegalArgumentException e) { log.debug("IllegalArgumentException authenticating with Google: " + e.toString()); externalId = null; } catch (Exception e) { log.debug("Unexpected exception authenticating with Google: " + e.toString()); externalId = null; } return externalId; }
From source file:uk.ac.cam.cl.dtg.segue.auth.FacebookAuthenticator.java
License:Apache License
/** * @param clientId The registered Facebook client ID * @param clientSecret The client secret provided by the Facebook api (https://developers.facebook.com/apps/) * @param callbackUri The callback url from the oauth process * @param requestedScopes The facebook permissions requested by this application *//*w ww. jav a2 s .c o m*/ @Inject public FacebookAuthenticator(@Named(Constants.FACEBOOK_CLIENT_ID) final String clientId, @Named(Constants.FACEBOOK_SECRET) final String clientSecret, @Named(Constants.FACEBOOK_CALLBACK_URI) final String callbackUri, @Named(Constants.FACEBOOK_OAUTH_SCOPES) final String requestedScopes) { this.jsonFactory = new JacksonFactory(); this.httpTransport = new NetHttpTransport(); this.clientSecret = clientSecret; this.clientId = clientId; this.callbackUri = callbackUri; this.requestedScopes = Arrays.asList(requestedScopes.split(",")); if (null == credentialStore) { credentialStore = new WeakHashMap<>(); } if (null == tokenVerifier) { tokenVerifier = new GoogleIdTokenVerifier(httpTransport, jsonFactory); } }
From source file:uk.ac.cam.cl.dtg.segue.auth.GoogleAuthenticator.java
License:Apache License
/** * Construct a google authenticator.// w w w . j a va 2 s . c o m * * @param clientSecretLocation * - external file containing the secret provided by the google service. * @param callbackUri * - The allowed URI for callbacks as registered with google. * @param requestedScopes * - The scopes that will be granted to Segue. * @throws IOException * - if we cannot load the secret file. */ @Inject public GoogleAuthenticator(@Named(Constants.GOOGLE_CLIENT_SECRET_LOCATION) final String clientSecretLocation, @Named(Constants.GOOGLE_CALLBACK_URI) final String callbackUri, @Named(Constants.GOOGLE_OAUTH_SCOPES) final String requestedScopes) throws IOException { this.jsonFactory = new JacksonFactory(); this.httpTransport = new NetHttpTransport(); Validate.notBlank(clientSecretLocation, "Missing resource %s", clientSecretLocation); // load up the client secrets from the file system. InputStream inputStream = new FileInputStream(clientSecretLocation); InputStreamReader isr = new InputStreamReader(inputStream); clientSecrets = GoogleClientSecrets.load(new JacksonFactory(), isr); this.requestedScopes = Arrays.asList(requestedScopes.split(";")); this.callbackUri = callbackUri; if (null == credentialStore) { credentialStore = CacheBuilder.newBuilder() .expireAfterAccess(CREDENTIAL_CACHE_TTL_MINUTES, TimeUnit.MINUTES).<String, Credential>build(); } if (null == tokenVerifier) { tokenVerifier = new GoogleIdTokenVerifier(httpTransport, jsonFactory); } }
From source file:uk.ac.cam.cl.dtg.segue.auth.GoogleAuthenticator.java
License:Apache License
/** * Construct a google authenticator with all of its required dependencies. * /*from w w w . ja va 2 s. c om*/ * @param clientSecret * - external file containing the secret provided by the google service. * @param callbackUri * - The allowed URI for callbacks as registered with google. * @param requestedScopes * - The scopes that will be granted to Segue. * @throws IOException * - if we cannot load the secret file. */ public GoogleAuthenticator(final GoogleClientSecrets clientSecret, @Named(Constants.GOOGLE_CALLBACK_URI) final String callbackUri, @Named(Constants.GOOGLE_OAUTH_SCOPES) final String requestedScopes) throws IOException { this.jsonFactory = new JacksonFactory(); this.httpTransport = new NetHttpTransport(); clientSecrets = clientSecret; this.requestedScopes = Arrays.asList(requestedScopes.split(";")); this.callbackUri = callbackUri; if (null == credentialStore) { credentialStore = CacheBuilder.newBuilder() .expireAfterAccess(CREDENTIAL_CACHE_TTL_MINUTES, TimeUnit.MINUTES).<String, Credential>build(); } if (null == tokenVerifier) { tokenVerifier = new GoogleIdTokenVerifier(httpTransport, jsonFactory); } }