com.google.api.client.util.store.AbstractDataStoreFactory Java Examples

The following examples show how to use com.google.api.client.util.store.AbstractDataStoreFactory. 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: GetUserProfile.java    From rides-java-sdk with MIT License 6 votes vote down vote up
/**
 * Creates an {@link OAuth2Credentials} object that can be used by any of the servlets.
 */
public static OAuth2Credentials createOAuth2Credentials(SessionConfiguration sessionConfiguration) throws Exception {




    // Store the users OAuth2 credentials in their home directory.
    File credentialDirectory =
            new File(System.getProperty("user.home") + File.separator + ".uber_credentials");
    credentialDirectory.setReadable(true, true);
    credentialDirectory.setWritable(true, true);
    // If you'd like to store them in memory or in a DB, any DataStoreFactory can be used.
    AbstractDataStoreFactory dataStoreFactory = new FileDataStoreFactory(credentialDirectory);

    // Build an OAuth2Credentials object with your secrets.
    return new OAuth2Credentials.Builder()
            .setCredentialDataStoreFactory(dataStoreFactory)
            .setRedirectUri(sessionConfiguration.getRedirectUri())
            .setClientSecrets(sessionConfiguration.getClientId(), sessionConfiguration.getClientSecret())
            .build();
}
 
Example #2
Source File: AuthModule.java    From nomulus with Apache License 2.0 5 votes vote down vote up
@Provides
public static GoogleAuthorizationCodeFlow provideAuthorizationCodeFlow(
    JsonFactory jsonFactory,
    GoogleClientSecrets clientSecrets,
    @Config("localCredentialOauthScopes") ImmutableList<String> requiredOauthScopes,
    AbstractDataStoreFactory dataStoreFactory) {
  try {
    return new GoogleAuthorizationCodeFlow.Builder(
        new NetHttpTransport(), jsonFactory, clientSecrets, requiredOauthScopes)
        .setDataStoreFactory(dataStoreFactory)
        .build();
  } catch (IOException ex) {
    throw new RuntimeException(ex);
  }
}
 
Example #3
Source File: AuthModule.java    From nomulus with Apache License 2.0 5 votes vote down vote up
@Provides
@Singleton
public static AbstractDataStoreFactory provideDataStoreFactory() {
  try {
    return new FileDataStoreFactory(DATA_STORE_DIR);
  } catch (IOException ex) {
    throw new RuntimeException(ex);
  }
}
 
Example #4
Source File: OAuth2Credentials.java    From rides-java-sdk with MIT License 4 votes vote down vote up
/**
 * Sets the Credential DataStore factory used for storing and loading Credentials per user.
 * Optional and defaults to an {@link MemoryDataStoreFactory}.
 */
public Builder setCredentialDataStoreFactory(AbstractDataStoreFactory credentialDataStoreFactory) {
    this.credentialDataStoreFactory = credentialDataStoreFactory;
    return this;
}