0

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();
pessolato
  • 1,472
  • 6
  • 14
  • I debugged the code and see only accessToken in the GoogleCredential object inside Directory. Dont see refreshToken in the response. Also see a expirationTime in Milliseconds 1424294867651 – user4390766 Feb 18 '15 at 20:28
  • Any help on this is greatly appreciated. Could not find any documentation on google on this case. There are information but not sure if it stands true for OAuth with service accounts. Trying to see how to handle the access token when you use OAuth 2.0 Service account and Directory API. We created a Google WebService interface and two applications make use of this API. APIs are mainly for User creation, management. Using Admin user to impersonate the GoogleCredential as this user only have permission to manage users. – user4390766 Feb 19 '15 at 15:34
  • Any one have any sample code on how they managed Tokens using ADMIN Directory API ? (Service account scenario) – user4390766 Mar 03 '15 at 14:52
  • did you find anything ? – TheMonkWhoSoldHisCode Dec 18 '16 at 12:22

0 Answers0