I am migrating code from GDATA API to Google ADMIN Directory API (User Provisioning). Migrated code is working fine with the new ADMIN API. Created a service account in Developers Console, then provided domain-wide access. Using below code to create the GoogleCredential object. Using a super admin user to impersonate the API call (Only this user have access to ADMIN API). I am using two-legged OAuth. GoogleCredential takes care of automatically "refreshing" the token so for each API call I am getting new Access token.
Do I need to use Data Store to persist access token ? Whats the advantages of using Data Store and is there any issues in not using DataStore while using OAuth 2.0 ? Is there any limitations on the number of access token that Google can support during a particular period of time ?
GoogleCredential credential = new GoogleCredential.Builder()
.setTransport(httpTransport)
.setJsonFactory(jsonFactory)
.setServiceAccountId(serviceAccountID)
.setServiceAccountScopes(scopes)
.setServiceAccountPrivateKeyFromP12File(new File(serciceAccountPKCSFilePath))
.setServiceAccountUser(serviceAccountUser)
.build();
// Create the Directory
Directory directory = new Directory.Builder(httpTransport, jsonFactory, credential) .setApplicationName(applicationName) .build();
// Makes the actual call to google to create user
user = directory.users().insert(user).execute();