title: Authenticate and get token for Azure Data Catalog using Java
body: <p>Here I am trying to register a Data Asset from Data Lake Store in the Azure Data Catalog.
  I am trying to get the authentication token for Azure Data Catalog which I will then set in header as below</p>
  
  <pre><code>request.setRequestProperty("Authorization","Bearer "+accesstoken);
  </code></pre>
  
  <p>Code I am using to get token</p>
  
  <pre><code>//This method sends request and gets the reponse
  public static String SetRequestAndGetResponse(HttpsURLConnection request, String payload)
  { 
      String accesstoken=null;
      ExecutorService service = null;
  
      Future&lt;AuthenticationResult&gt; FutureResult;
      AuthenticationResult result;
      AuthenticationCallback callback = null;
  
      //Creating the credential object for DataCatalog with Client ID and Client secret picked up from the vault
  
      ClientCredential credential = new ClientCredential("client_ID", "client_secret");
  
      try
      {
          service = Executors.newFixedThreadPool(1);
          AuthenticationContext context = new AuthenticationContext("https://login.windows.net/tenant_ID/oauth2/token",true,service);
  
          /* 
           * getting the authentication result object using the App ID URI from Azure AD as suggested in
           * 
           * https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-protocols-oauth-code
           */
  
          FutureResult = context.acquireToken("App ID URI from Azure AD/login/aad", credential,null);
          while(!(FutureResult.isDone()))
          {}
          accesstoken=FutureResult.get().getAccessToken();
          //System.out.println("result "+accesstoken);
      }
      catch(Exception e)
      {System.out.println("ex "+e.getMessage());
      e.printStackTrace();}
  </code></pre>
  
  <p>But , I am getting exception as shown below</p>
  
  <p>ex com.microsoft.aad.adal4j.AuthenticationException:<br>
  {"error_description":"AADSTS50001: The application named https://abc.onmicrosoft.com/somecode/login/aad was not found in the tenant named tenant_id.<br>
  This can happen if the application has not been installed by the administrator of the tenant or consented to by any user in the tenant.<br>
  You might have sent your authentication request to the wrong tenant.</p>
  
  <p>Trace ID: some_id</p>
  
  <p>Correlation ID: some_id</p>
  
  <p>Timestamp: 2017-04-06 09:57:01Z","error":"invalid_resource"}</p>
  
  <p>at com.microsoft.aad.adal4j.AdalTokenRequest.executeOAuthRequestAndProcessResponse(AdalTokenRequest.java:107)</p>
  
  <p>at com.microsoft.aad.adal4j.AuthenticationContext.acquireTokenCommon(AuthenticationContext.java:816)</p>
  
  <p>at com.microsoft.aad.adal4j.AuthenticationContext.access$100(AuthenticationContext.java:64)</p>
  
  <p>at com.microsoft.aad.adal4j.AuthenticationContext$1.call(AuthenticationContext.java:172)</p>
  
  <p>at com.microsoft.aad.adal4j.AuthenticationContext$1.call(AuthenticationContext.java:161)</p>
  
  <p>at java.util.concurrent.FutureTask.run(FutureTask.java:266)</p>
  
  <p>at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)</p>
  
  <p>at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)</p>
  
  <p>at java.lang.Thread.run(Thread.java:745)</p>
  
  <p>***************** EDIT *******************
  Thanks! But, I tried with "<a href="https://graph.windows.net" rel="nofollow noreferrer">https://graph.windows.net</a>" as resource URI to get token using authentication context but still server responds as unauthorized request.
  By the way, I am using below snippet to create a request object.</p>
  
  <pre><code>String fullUri = String.format("https://api.azuredatacatalog.com/catalogs/"+catalogName+"/views/tables?api-version=2016-03-30");
      URL url = null;
      try {
          //sETTING UP url connection to azure data catalog api 
          url = new URL(fullUri);
      } catch (MalformedURLException e) {
          // TODO Auto-generated catch block
          System.out.println("Malformed URL Exception");
      }
      HttpsURLConnection request;
      try {
          request = (HttpsURLConnection) url.openConnection();
          }
          catch(Exception e){ e.printStackTrace();}
  </code></pre>
  
  <p>Please help me on how do I get this fixed.</p>
  
  <p>Thanks.</p>