/** * 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(); }
.setRedirectUri("http://redirect") .setHttpTransport(mockHttpTransport) .setCredentialDataStoreFactory(mockDataStoreFactory) .setScopes(Arrays.asList(Scope.PROFILE, Scope.REQUEST)) .build();
/** * Creates an {@link OAuth2Credentials} object that can be used by any of the servlets. * * Throws an {@throws IOException} when no client ID or secret found in secrets.properties */ static OAuth2Credentials createOAuth2Credentials(SessionConfiguration config) throws IOException { return new OAuth2Credentials.Builder() .setCredentialDataStoreFactory(MemoryDataStoreFactory.getDefaultInstance()) .setRedirectUri(config.getRedirectUri()) .setScopes(config.getScopes()) .setClientSecrets(config.getClientId(), config.getClientSecret()) .build(); }