Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/323.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/azure/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Java对Azure数据目录进行身份验证并获取令牌_Java_Azure_Azure Data Catalog - Fatal编程技术网

使用Java对Azure数据目录进行身份验证并获取令牌

使用Java对Azure数据目录进行身份验证并获取令牌,java,azure,azure-data-catalog,Java,Azure,Azure Data Catalog,在这里,我试图在Azure数据目录中注册Data Lake Store中的数据资产。 我正在尝试获取Azure数据目录的身份验证令牌,然后在标题中设置该令牌,如下所示 request.setRequestProperty("Authorization","Bearer "+accesstoken); 我用来获取令牌的代码 //This method sends request and gets the reponse public static String SetRequestAndGetR

在这里,我试图在Azure数据目录中注册Data Lake Store中的数据资产。 我正在尝试获取Azure数据目录的身份验证令牌,然后在标题中设置该令牌,如下所示

request.setRequestProperty("Authorization","Bearer "+accesstoken);
我用来获取令牌的代码

//This method sends request and gets the reponse
public static String SetRequestAndGetResponse(HttpsURLConnection request, String payload)
{ 
    String accesstoken=null;
    ExecutorService service = null;

    Future<AuthenticationResult> 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();}
请帮我把这个修好

谢谢。

方法的第一个参数应该是图形资源,而不是Azure AD中的应用程序ID URI

请更改代码行,如下所示:

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

有关更多信息,请参阅:

以下是您应该使用的:

string authorityUri = "https://login.windows.net/common/oauth2/authorize";
AuthenticationContext authContext = new AuthenticationContext(authorityUri);

另外,传递给
AcquireToken
方法的资源字符串应该是“.”

谢谢!但是,我试过了,但服务器仍然以未经授权的请求响应。我已经补充了关于这个问题的更多细节
string authorityUri = "https://login.windows.net/common/oauth2/authorize";
AuthenticationContext authContext = new AuthenticationContext(authorityUri);