【问题标题】:rest api unauthorized Azure Data Catalogrest api 未经授权的 Azure 数据目录
【发布时间】:2016-10-24 08:49:46
【问题描述】:

我正在使用我组织的 Azure 数据目录。我不是目录的创建者/管理员/所有者,但我有权从 Web 界面注册/删除目录。

我想为 Azure 数据目录使用 REST API。在我的许可级别下可以吗? 我已经按照https://msdn.microsoft.com/en-us/library/mt428033.aspx 的所有步骤编写了以下代码:

class Program
{
    static void Main(string[] args)
    {
        string url = "https://api.azuredatacatalog.com/catalogs/DefaultCatalog/search/search?searchTerms=My_Server&count=10&startPage=1&api-version=2016-03-30";

        HttpWebRequest request = System.Net.WebRequest.Create(url) as System.Net.HttpWebRequest;


        Console.WriteLine(AccessToken().CreateAuthorizationHeader());


        try
        {
            WebResponse response = request.GetResponse();
            Console.WriteLine(response.ContentLength);
        }
        catch (Exception e)
        {
            Console.WriteLine(e);
        }

        Console.ReadKey();
    }

    static AuthenticationResult AccessToken()
    {
        string resourceUri = "https://datacatalog.azure.com";

        string clientId = "my-client-id";

        string redirectUri = "my-redirect-uri";

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

        return authContext.AcquireToken(resourceUri, clientId, new Uri(redirectUri), PromptBehavior.RefreshSession);

    }
}

当我尝试从 API 运行搜索时,我收到以下错误:

System.Net.WebException:远程服务器返回错误:(401) 未经授权。在 System.Net.HttpWebRequest.GetResponse() 在 HRBIADCAPI.Program.Main(String[] args) 在 c:\users\naghimir\documents\visual studio 2015\Projects\HRBIADCAPI\HRBIADCAPI\Program.cs:第 32 行

现在我认为问题在于我没有授予对创建用于读取/写入数据目录的客户端程序的访问权限(我在 Azure 数据工厂中所做的),但文档中也没有该步骤。

我需要成为所有者还是可以请求所有者的许可才能使用 Azure 数据目录 API?

【问题讨论】:

    标签: rest azure azure-data-factory azure-data-catalog


    【解决方案1】:

    根据描述,您使用 OAuth 2.0 代码授权流程授权应用委托用户操作 Azure 数据目录。

    为确保请求正常运行,我们需要将范围授予应用程序,如下图所示:

    由于应用只委托用户的权限,请确保用户有足够的权限来手动操作资源。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-08-13
      • 1970-01-01
      • 1970-01-01
      • 2013-11-19
      • 1970-01-01
      • 1970-01-01
      • 2021-04-07
      • 1970-01-01
      相关资源
      最近更新 更多