com.google.api.client.extensions.java6.auth.oauth2.VerificationCodeReceiver Java Examples

The following examples show how to use com.google.api.client.extensions.java6.auth.oauth2.VerificationCodeReceiver. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: StorageSample.java    From cloud-storage-docs-json-api-examples with Apache License 2.0 5 votes vote down vote up
/** Authorizes the installed application to access user's protected data. */
private static Credential authorize() throws Exception {
  // Load client secrets.
  GoogleClientSecrets clientSecrets = null;
  try {
    clientSecrets = GoogleClientSecrets.load(JSON_FACTORY,
        new InputStreamReader(StorageSample.class.getResourceAsStream(String.format("/%s",CLIENT_SECRET_FILENAME))));
    if (clientSecrets.getDetails().getClientId() == null ||
        clientSecrets.getDetails().getClientSecret() == null) {
        throw new Exception("client_secrets not well formed.");
    }
  } catch (Exception e) {
    System.out.println("Problem loading client_secrets.json file. Make sure it exists, you are " + 
                      "loading it with the right path, and a client ID and client secret are " +
                      "defined in it.\n" + e.getMessage());
    System.exit(1);
  }

  // Set up authorization code flow.
  // Ask for only the permissions you need. Asking for more permissions will
  // reduce the number of users who finish the process for giving you access
  // to their accounts. It will also increase the amount of effort you will
  // have to spend explaining to users what you are doing with their data.
  // Here we are listing all of the available scopes. You should remove scopes
  // that you are not actually using.
  Set<String> scopes = new HashSet<String>();
  scopes.add(StorageScopes.DEVSTORAGE_FULL_CONTROL);
  scopes.add(StorageScopes.DEVSTORAGE_READ_ONLY);
  scopes.add(StorageScopes.DEVSTORAGE_READ_WRITE);

  GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
      httpTransport, JSON_FACTORY, clientSecrets, scopes)
      .setDataStoreFactory(dataStoreFactory)
      .build();
  // Authorize.
  VerificationCodeReceiver receiver = 
      AUTH_LOCAL_WEBSERVER ? new LocalServerReceiver() : new GooglePromptReceiver();
  return new AuthorizationCodeInstalledApp(flow, receiver).authorize("user");    
}
 
Example #2
Source File: GoogleAuthorizationDialog.java    From hop with Apache License 2.0 4 votes vote down vote up
public GoogleAuthorizationDialog( Shell shell, VerificationCodeReceiver receiver ) {
  super( shell );
  this.receiver = receiver;
}
 
Example #3
Source File: CustomAuthorizationCodeInstalledApp.java    From hop with Apache License 2.0 4 votes vote down vote up
public CustomAuthorizationCodeInstalledApp( AuthorizationCodeFlow flow, VerificationCodeReceiver receiver ) {
  super( flow, receiver );
}
 
Example #4
Source File: AuthorizationCodeInstalledAppTalend.java    From components with Apache License 2.0 4 votes vote down vote up
public AuthorizationCodeInstalledAppTalend(AuthorizationCodeFlow flow, VerificationCodeReceiver receiver) {
    super(flow, receiver);
}
 
Example #5
Source File: GoogleAuthorizationDialog.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public GoogleAuthorizationDialog( Shell shell, VerificationCodeReceiver receiver ) {
  super( shell );
  this.receiver = receiver;
}
 
Example #6
Source File: CustomAuthorizationCodeInstalledApp.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public CustomAuthorizationCodeInstalledApp( AuthorizationCodeFlow flow, VerificationCodeReceiver receiver ) {
  super( flow, receiver );
}