I am migrating code from GDATA API to Google ADMIN Directory API (User Provisioning). Migrated code is working fine with the new ADMIN API. I created a service account in Developers Console, then provided it domain-wide access, using the code below to create the GoogleCredential object. I am using two-legged OAuth. GoogleCredential takes care of automatically "refreshing" the token so for each API call I am getting new an Access token. Do I need to use Datastore to persist access token? Whats the advantages of using Datastore and is there any issues in not using Datastore while using OAuth 2.0 ?
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();