HttpTransport httpTransport = new NetHttpTransport(); JsonFactory jsonFactory = new JacksonFactory(); GoogleCredential credential = new GoogleCredential.Builder() .setTransport(httpTransport) .setJsonFactory(jsonFactory) .setClientSecrets("client_id", "client_secret").build(); credential.setAccessToken("access_token");
@JsonRequest @Path("/login_with_google") public Response<WebUser> loginWithGoogle(@ApiParam("access_token") String accessToken) { GoogleCredential credential = new GoogleCredential().setAccessToken(accessToken); Oauth2 oauth2 = new Oauth2.Builder(new NetHttpTransport(), new JacksonFactory(), credential).setApplicationName("Oauth2").build(); Userinfoplus userinfo; try { userinfo = oauth2.userinfo().get().execute(); if (!userinfo.getVerifiedEmail()) { throw new RakamException("The Google email must be verified", BAD_REQUEST); } Optional<WebUser> userByEmail = service.getUserByEmail(userinfo.getEmail()); WebUser user = userByEmail.orElseGet(() -> service.createUser(userinfo.getEmail(), null, userinfo.getGivenName(), userinfo.getGender(), userinfo.getLocale(), userinfo.getId(), false)); return getLoginResponseForUser(encryptionConfig.getSecretKey(), user, config.getCookieDuration()); } catch (IOException e) { LOGGER.error(e); throw new RakamException("Unable to login", INTERNAL_SERVER_ERROR); } }
public Credential build() { return new GoogleCredential().setAccessToken(accessToken); } }
public Credential build() { return new GoogleCredential().setAccessToken(accessToken); } }
... // this should all be in a separate thread (e.g. AsyncTask) final String token = GoogleAuthUtil.getToken(context, email, scope); GoogleCredential credential = new GoogleCredential(); credential.setAccessToken(token); Tasks service = new Tasks.Builder(transport, jsonFactory, credential) .setApplicationName("Google-TasksAndroidSample/1.0") .setJsonHttpRequestInitializer(new GoogleKeyInitializer(ClientCredentials.KEY)) .build(); List<String> result = new ArrayList<String>(); Tasks.TasksOperations.List listRequest = service.tasks().list("@default"); listRequest.setFields("items/title"); List<Task> tasks = listRequest.execute().getItems(); ...
String accessToken = GoogleAuthUtil.getToken(context, accountName, OAUTH2_SCOPE); final GoogleCredential credential = new GoogleCredential(); credential.setAccessToken(accessToken); Drive driveConnection = new Drive.Builder(AndroidHttp.newCompatibleTransport(), new GsonFactory(), credential).setApplicationName(APP_NAME).build();
GoogleCredential credential1 = new GoogleCredential.Builder().setJsonFactory(jsonFactory) .setTransport(httpTransport).setClientSecrets(CLIENT_ID, CLIENT_SECRET).build(); credential1.setAccessToken(accessToken); credential1.setRefreshToken(refreshToken); Drive service = new Drive.Builder(httpTransport, jsonFactory, credential1).build();
GoogleCredential credential = new GoogleCredential.Builder().setTransport(new NetHttpTransport()) .setJsonFactory(JacksonFactory.getDefaultInstance()) .build(); credential.setAccessToken(GoogleSignInAccount.getIdToken());
gc.setAccessToken(tokenResponse.getAccessToken());
private static Credential authorize(GuildSettings g) throws Exception { if (g.getEncryptedAccessToken().equalsIgnoreCase("N/a")) throw new IllegalAccessException("Guild does not have proper access token!"); AESEncryption encryption = new AESEncryption(g); String accessToken = Authorization.getAuth().requestNewAccessToken(g, encryption); GoogleCredential credential = new GoogleCredential(); credential.setAccessToken(accessToken); return credential; }
public Optional<Credential> load() { Properties properties = new Properties(); try { File file = getAuthenticationFile(options); if(!file.exists() || !file.canRead()) { LOGGER.log(Level.FINE, "Cannot find or read properties file. Returning empty credentials."); return Optional.empty(); } properties.load(new FileReader(file)); HttpTransport httpTransport = new NetHttpTransport(); JsonFactory jsonFactory = new JacksonFactory(); GoogleCredential credential = new GoogleCredential.Builder().setJsonFactory(jsonFactory) .setTransport(httpTransport).setClientSecrets(OAuth2ClientCredentials.CLIENT_ID, OAuth2ClientCredentials.CLIENT_SECRET).build(); credential.setAccessToken(properties.getProperty(PROP_ACCESS_TOKEN)); credential.setRefreshToken(properties.getProperty(PROP_REFRESH_TOKEN)); return Optional.of(credential); } catch (IOException e) { throw new JDriveSyncException(JDriveSyncException.Reason.IOException, "Failed to load properties file: " + e.getMessage(), e); } }
.setServiceAccountPrivateKeyFromP12File(new File("resources\\xyz.p12")) .setServiceAccountScopes(Collections.singleton(BloggerScopes.BLOGGER)).build(); credential.setAccessToken(response.getAccessToken()); return credential;
/** * Retrieve OAuth 2.0 credentials. * * @return OAuth 2.0 Credential instance. * @throws IOException */ private Credential getCredentials() throws IOException { String code = tokenField.getText(); HttpTransport transport = new NetHttpTransport(); JacksonFactory jsonFactory = new JacksonFactory(); String CLIENT_SECRET = "EPME5fbwiNLCcMsnj3jVoXeY"; // Step 2: Exchange --> GoogleTokenResponse response = new GoogleAuthorizationCodeTokenRequest( transport, jsonFactory, CLIENT_ID, CLIENT_SECRET, code, REDIRECT_URI).execute(); // End of Step 2 <-- // Build a new GoogleCredential instance and return it. return new GoogleCredential.Builder() .setClientSecrets(CLIENT_ID, CLIENT_SECRET) .setJsonFactory(jsonFactory).setTransport(transport).build() .setAccessToken(response.getAccessToken()) .setRefreshToken(response.getRefreshToken()); }
/** * Creates a Google Contacts Service object which can be used to make requests via the SDK. This uses * Oauth2 access tokens and refresh tokens. * * @param messageContext The message context for the connector request. * @return A Contacts Service object * @throws IOException Signals that an I/O exception has occurred. */ protected final ContactsService getContactService(final MessageContext messageContext) throws IOException { final HttpTransport transport = new NetHttpTransport(); final JsonFactory jsonFactory = new JacksonFactory(); final GoogleCredential credential = new GoogleCredential.Builder().setTransport(transport).setJsonFactory(jsonFactory).build() .setAccessToken((String) messageContext.getProperty(Constants.ACCESS_TOKEN)); final ContactsService contactsService = new ContactsService((String) messageContext.getProperty(Constants.APP_NAME)); contactsService.setOAuth2Credentials(credential); return contactsService; }
/** * Instantiates a new google contacts direct invoker. * * @param accessToken the access token * @param appName the app name */ public GoogleContactsDirectInvoker(final String accessToken, final String appName) { final HttpTransport transport = new NetHttpTransport(); final JsonFactory jsonFactory = new JacksonFactory(); final GoogleCredential credential = new GoogleCredential.Builder().setTransport(transport).setJsonFactory(jsonFactory).build() .setAccessToken(accessToken); directInvokerContactsService = new ContactsService(appName); directInvokerContactsService.setOAuth2Credentials(credential); }
@Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); Enum<?> downloadFormat = TestDownloadFormat.CSV; Mockito.<Enum<?>>when(reportRequest.getDownloadFormat()).thenReturn(downloadFormat); credential = new GoogleCredential.Builder().setTransport(new NetHttpTransport()) .setJsonFactory(new JacksonFactory()).build(); credential.setAccessToken("TEST_ACCESS_TOKEN"); AdWordsSession session = new AdWordsSession.Builder() .withUserAgent("TEST_APP") .withOAuth2Credential(credential) .withEndpoint(testHttpServer.getServerUrl()) .withDeveloperToken("TEST_DEVELOPER_TOKEN") .withClientCustomerId("TEST_CLIENT_CUSTOMER_ID") .build(); helper = new GenericAdWordsServices() .getBootstrapper() .getInstanceOf(session, AdHocReportDownloadHelper.class); exceptionBuilder = DetailedReportDownloadResponseException::new; }