Package com.google.api.client.googleapis.auth.oauth2.GoogleIdToken

Examples of com.google.api.client.googleapis.auth.oauth2.GoogleIdToken.Payload


      }
      // set up file credential store
      FileCredentialStore credentialStore = new FileCredentialStore(
          new File(System.getProperty("user.home"), ".credentials/calendar.json"), JSON_FACTORY);
      // set up authorization code flow
      GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
          HTTP_TRANSPORT, JSON_FACTORY, clientSecrets,
          Collections.singleton(CalendarScopes.CALENDAR)).setCredentialStore(credentialStore).build();
      // authorize
      return new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize("user");
    }
View Full Code Here


      throws IOException {
    HttpTransport httpTransport = new NetHttpTransport();
    JsonFactory jsonFactory = new JacksonFactory();
    Collection<String> scopes = Arrays.asList(OAUTH2_SCOPE);
    GoogleClientSecrets clientSecrets = getClientSecrets();
    GoogleAuthorizationCodeFlow flow;
    if (usePersistedCredentials) {
      flow = new GoogleAuthorizationCodeFlow.Builder(
        httpTransport, jsonFactory, clientSecrets, scopes).setAccessType("offline")
        .setApprovalPrompt("force").setCredentialStore(getCredentialStore(jsonFactory)).build();
    } else {
View Full Code Here

     * as long as the credentials file is not removed.
     */
    private Credential authorize(String clientId, String clientSecret, Collection<String> scopes) throws Exception {
        dataStoreFactory = new FileDataStoreFactory(DATA_STORE_DIR);
        // set up authorization code flow
        GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(transport, jsonFactory, clientId, clientSecret, scopes)
            .setDataStoreFactory(dataStoreFactory)
            .setAccessType("offline")
            .build();
        // authorize
        return new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize("user");
View Full Code Here

    this.historyName = history > 0 ? backupName + " " + new SimpleDateFormat("yyyy.MM.dd_HH.mm.ss").format(new Date()) : null;

    final HttpTransport httpTransport = new NetHttpTransport();
    final JsonFactory jsonFactory = new JacksonFactory();

    final GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(httpTransport, jsonFactory, googleDriveOptions.getClientID(), googleDriveOptions.getClientSecret(),
        Arrays.asList(DriveScopes.DRIVE)).setAccessType("offline").setApprovalPrompt("auto").build();

    this.clientTokenPath = Paths.get(googleDriveOptions.getClientTokenPath());

    try {
      final String clientTokenAsJson = Files.exists(this.clientTokenPath) ? FileUtils.readFileToString(this.clientTokenPath.toFile()) : null;

      credential = new GoogleCredential.Builder().setTransport(new NetHttpTransport()).setJsonFactory(new GsonFactory())
          .setClientSecrets(googleDriveOptions.getClientID(), googleDriveOptions.getClientSecret()).build();

      if (StringUtils.isEmpty(clientTokenAsJson)) {

        final String url = flow.newAuthorizationUrl().setRedirectUri(REDIRECT_URL).build();
        System.out.println("Please open the following URL in your browser, copy the authorization code and enter below.");
        System.out.println("\n" + url + "\n");
        final String code = new BufferedReader(new InputStreamReader(System.in)).readLine().trim();

        clientToken = flow.newTokenRequest(code).setRedirectUri(REDIRECT_URL).execute();

        storeClientToken(jsonFactory);
        LOGGER.log(Level.INFO, "client token stored in '" + this.clientTokenPath + "'");
      } else {
View Full Code Here

        checkClientSecretsFile(clientSecrets);

        dataStoreFactory = new FileDataStoreFactory(DATA_STORE_DIR);

        // set up authorization code flow
        GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow
                .Builder(HTTP_TRANSPORT,
                        JSON_FACTORY, clientSecrets,
                        Collections.singleton(AndroidPublisherScopes.ANDROIDPUBLISHER))
                        .setDataStoreFactory(dataStoreFactory).build();
        // authorize
View Full Code Here

        // This creates the credentials datastore at ~/.oauth-credentials/${credentialDatastore}
        FileDataStoreFactory fileDataStoreFactory = new FileDataStoreFactory(new File(System.getProperty("user.home") + "/" + CREDENTIALS_DIRECTORY));
        DataStore<StoredCredential> datastore = fileDataStoreFactory.getDataStore(credentialDatastore);

        GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
                HTTP_TRANSPORT, JSON_FACTORY, clientSecrets, scopes).setCredentialDataStore(datastore)
                .build();

        // Build the local server and bind it to port 8080
        LocalServerReceiver localReceiver = new LocalServerReceiver.Builder().setPort(8080).build();
View Full Code Here

  private Credential authorize() throws Exception {
    // set up file credential store
    final FileCredentialStore credentialStore = new FileCredentialStore(
        new File(System.getProperty("user.home"), ".credentials/calendar.json"), jsonFactory);
    // set up authorization code flow
    final GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
        httpTransport, jsonFactory, GOOGLE_CLIENT_ID, GOOGLE_CLIENT_SECRET, Collections.singleton(CalendarScopes.CALENDAR))
      .setCredentialStore(credentialStore)
      .build();
    // authorize
    return new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize("user");
View Full Code Here

    GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(
        JSON_FACTORY,
        Auth.class.getResourceAsStream("/client_secrets.json"));

    GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
        HTTP_TRANSPORT, JSON_FACTORY, clientSecrets, scopes)
        .setCredentialStore(credentialStore).build();

    // TODO change this to remove the port
    LocalServerReceiver localReceiver = new LocalServerReceiver.Builder()
View Full Code Here

  private static void authorize(DataStoreFactory storeFactory, String userName) throws Exception {
    // Depending on your application, there may be more appropriate ways of
    // performing the authorization flow (such as on a servlet), see
    // https://code.google.com/p/google-api-java-client/wiki/OAuth2#Authorization_Code_Flow
    // for more information.
    GoogleAuthorizationCodeFlow authorizationFlow = new GoogleAuthorizationCodeFlow.Builder(
        new NetHttpTransport(),
        new JacksonFactory(),
        CLIENT_ID,
        CLIENT_SECRET,
        Lists.newArrayList(SCOPE))
        .setDataStoreFactory(storeFactory)
        // Set the access type to offline so that the token can be refreshed.
        // By default, the library will automatically refresh tokens when it
        // can, but this can be turned off by setting
        // api.dfa.refreshOAuth2Token=false in your ads.properties file.
        .setAccessType("offline").build();

    String authorizeUrl =
        authorizationFlow.newAuthorizationUrl().setRedirectUri(CALLBACK_URL).build();
    System.out.println("Paste this url in your browser: \n" + authorizeUrl + '\n');

    // Wait for the authorization code.
    System.out.println("Type the code you received here: ");
    String authorizationCode = new BufferedReader(new InputStreamReader(System.in)).readLine();

    // Authorize the OAuth2 token.
    GoogleAuthorizationCodeTokenRequest tokenRequest =
        authorizationFlow.newTokenRequest(authorizationCode);
    tokenRequest.setRedirectUri(CALLBACK_URL);
    GoogleTokenResponse tokenResponse = tokenRequest.execute();

    // Store the credential for the user.
    authorizationFlow.createAndStoreCredential(tokenResponse, userName);
  }
View Full Code Here

  }

  private static DfaSession createDfaSession(DataStoreFactory storeFactory, String userId)
      throws IOException, ValidationException, ConfigurationLoadException {
    // Create a GoogleCredential with minimal information.
    GoogleAuthorizationCodeFlow authorizationFlow = new GoogleAuthorizationCodeFlow.Builder(
        new NetHttpTransport(),
        new JacksonFactory(),
        CLIENT_ID,
        CLIENT_SECRET,
        Lists.newArrayList(SCOPE))
        .setDataStoreFactory(storeFactory).build();

    // Load the credential.
    Credential credential = authorizationFlow.loadCredential(userId);

    // Construct a DfaSession.
    return new DfaSession.Builder()
        .fromFile()
        .withUsernameAndOAuth2Credential(userId, credential)
View Full Code Here

TOP

Related Classes of com.google.api.client.googleapis.auth.oauth2.GoogleIdToken.Payload

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.