Authenticate and get token for Azure Data Catalog using Java -


here trying register data asset data lake store in azure data catalog. trying authentication token azure data catalog set in header below

request.setrequestproperty("authorization","bearer "+accesstoken); 

code using token

//this method sends request , gets reponse public static string setrequestandgetresponse(httpsurlconnection request, string payload) {      string accesstoken=null;     executorservice service = null;      future<authenticationresult> futureresult;     authenticationresult result;     authenticationcallback callback = null;      //creating credential object datacatalog client id , client secret picked 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 authentication result object using app id uri azure ad suggested in          *           * https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-protocols-oauth-code          */          futureresult = context.acquiretoken("app id uri 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();} 

but , getting exception shown below

ex com.microsoft.aad.adal4j.authenticationexception:
{"error_description":"aadsts50001: application named https://abc.onmicrosoft.com/somecode/login/aad not found in tenant named tenant_id.
can happen if application has not been installed administrator of tenant or consented user in tenant.
might have sent authentication request wrong tenant.

trace id: some_id

correlation id: some_id

timestamp: 2017-04-06 09:57:01z","error":"invalid_resource"}

at com.microsoft.aad.adal4j.adaltokenrequest.executeoauthrequestandprocessresponse(adaltokenrequest.java:107)

at com.microsoft.aad.adal4j.authenticationcontext.acquiretokencommon(authenticationcontext.java:816)

at com.microsoft.aad.adal4j.authenticationcontext.access$100(authenticationcontext.java:64)

at com.microsoft.aad.adal4j.authenticationcontext$1.call(authenticationcontext.java:172)

at com.microsoft.aad.adal4j.authenticationcontext$1.call(authenticationcontext.java:161)

at java.util.concurrent.futuretask.run(futuretask.java:266)

at java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1142)

at java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:617)

at java.lang.thread.run(thread.java:745)

***************** edit ******************* thanks! but, tried "https://graph.windows.net" resource uri token using authentication context still server responds unauthorized request. way, using below snippet create request object.

string fulluri = string.format("https://api.azuredatacatalog.com/catalogs/"+catalogname+"/views/tables?api-version=2016-03-30");     url url = null;     try {         //setting url connection 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();} 

please me on how fixed.

thanks.

the first parameter of authenticationcontext.acquiretoken method should graph resource instead of app id uri azure ad.

please change line of code below:

futureresult = context.acquiretoken("https://graph.windows.net", credential, null); 

for more info, see: https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-devquickstarts-webapp-java


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -