oauthgoogle-oauthgoogle-oauth-java-clientgoogle-email-settings-api

Email Settings API - ClientLogin


We are using EMAIL Settings API and ClientLogin for Authentication. EMAIL Settings API is still on GDATA Libraries. Using GDATA libraries can we start using OAuth 2.0 ? (we are using the appsforyourdomain client library to use EMAIL Settings API) Or can we continue using ClientLogin ? Based on the post looks like ClientLogin is going to retire by April 20, 2015. Please guide me the right approach. GDATA API : 1.46.0. EMAIL Settings API is used only for disabling the webclips for the user.


Solution

  • We were using GDATA API 1.46.0 and it does not support OAuth 2.0 . Support was added in 1.47.0 version. See the release note below. After using the new Libraries I was able to implement OAuth 2.0. Used GmailSettingsService class inside the appsforyourdomain client library and commented out the ClientLogin flow and added new flow for OAuth2.0. Use GoogleCredential Object to create the OAuth2.0 credential object.

    //  Client Login
    //  this.setUserCredentials(username + "@" + domain, password);
    
    //  OAuth 2.0
    this.setOAuth2Credentials(initCredential());
    
    public static GoogleCredential initCredential() throws GeneralSecurityException, IOException {
          httpTransport = GoogleNetHttpTransport.newTrustedTransport();
    
        List<String> scopes = Arrays.asList("https://apps-apis.google.com/a/feeds/emailsettings/2.0/");
    
        credential = new GoogleCredential.Builder()
            .setTransport(httpTransport)
            .setJsonFactory(JSON_FACTORY)
            .setServiceAccountId(SERVICE_ACCOUNT_EMAIL)
            .setServiceAccountScopes(scopes)
            .setServiceAccountPrivateKeyFromP12File(new File(SERVICE_ACCOUNT_PKCS12_FILE_PATH))
            .setServiceAccountUser(DOMAIN_ADMIN_API_USER)
            .build();  
        return credential;
      }
    

    Notes for v1.47.0

    o Add OAuth 2.0 support leveraging Google OAuth Client for Java (http://code.google.com/p/google-oauth-java-client/).