title: Switching from username/password to OAuth 2 in Java application using Google Directory API
body: <p>I do the following in a java application to authenticate my client and multi-client.</p>
  
  <pre><code>  AppsForYourDomainClient client = null;
    ProvisioningApiMultiDomainSampleClient multiClient = null;
    try {
       client = new AppsForYourDomainClient("someUserName@email.com", "password", "email.com");
  
       multiClient = new ProvisioningApiMultiDomainSampleClient("someUserName@email.com", "password", "email.com","multidomain-api-sample-email.com");
  
    } catch (Exception ex) {
          ex.printStackTrace();   
    }  
  </code></pre>
  
  <p>I want to switch to OAuth 2 authentication. Also AppsForYourDomainClient and ProvisioningApiMultiDomainSampleClient are being deprecated. How do I move forward with authenticating with OAuth2 and the new Google Directory API?</p>
  
  <p>What I was needing was examples. There seems to be plenty of documentation but very little example.</p>
  
  <p>Luckily I found this:
  <a href="https://stackoverflow.com/questions/25383591/create-gmail-account-for-a-domain-using-google-admin-sdk-directory-api-in-java">Create gmail account for a domain using Google Admin SDK Directory API in Java</a></p>
  
  <p>Which points me in the right direction. And I hope if this post comes up on any searches, then they can refer to the link above.</p>
  
  <p>Thanks</p>