[Azure DataCatalog]:从 Azure 数据目录词汇表中读取数据未授权错误?
[Azure DataCatalog]: Read the data from Azure data catalog glossary Unauthorized error?
我尝试 post Azure 数据目录中的 excel 数据。我是在控制台应用程序中编写的。
我的密码是
static void Main()
{
string DefaultCatalog = "DefaultCatalog";
string DefaultGlossary = "DefaultGlossary";
string fullUri = string.Format("https://api.azuredatacatalog.com/catalogs/{0}/glossaries/{1}/terms?api-version=2016-03-30",
DefaultCatalog, DefaultGlossary);
HttpWebRequest request = WebRequest.Create(fullUri) as HttpWebRequest;
request.KeepAlive = true;
request.Method = "GET";
request.Accept = "application/json;adc.metadata=full";
request.Headers.Add("Authorization", AccessToken().Result.CreateAuthorizationHeader());
request.AllowAutoRedirect = false;
HttpWebResponse response = request.GetResponse() as HttpWebResponse;
if (response != null && response.StatusCode == HttpStatusCode.Redirect)
{
using (var reader = new StreamReader(response.GetResponseStream()))
{
var itemPayload = reader.ReadToEnd();
JToken terms;
JObject.Parse(itemPayload).TryGetValue("value", out terms);
if (terms != null)
{
var r = JsonConvert.DeserializeObject<JArray>(terms.ToString());
}
}
}
}
static async Task<AuthenticationResult> AccessToken()
{
string clientId = "MyClientId";
string client_secret = "MyClientSecret";
string tenentId = "MytenentId";
if (_authResult == null)
{
// Resource Uri for Data Catalog API
string resourceUri = "https://api.azuredatacatalog.com/";
string redirectUri = "https://login.live.com/oauth20_desktop.srf";
string authorityUri = "https://login.windows.net/MytenentId/oauth2/authorize";
AuthenticationContext authContext = new AuthenticationContext(authorityUri);
_authResult = await authContext.AcquireTokenAsync(resourceUri, clientId, new Uri(redirectUri), new PlatformParameters(PromptBehavior.Always));
//ClientCredential cc = new ClientCredential(clientId, client_secret);
//_authResult = await authContext.AcquireTokenAsync(resourceUri, cc);
}
return _authResult;
}
我想从我的 azure datacatalog 中获取词汇表列表。但它总是返回未经授权的错误。
"The remote server returned an error: (403) Forbidden."
我的错误是
您需要使用来获取正确的令牌:
字符串 authorityUri = "https://login.windows.net/common/oauth2/authorize";
希望这对您有所帮助,
莫妮卡
确保您在词汇表管理员列表中。
此外,ADC 在 github 中也有很好的代码示例,可以满足您的需求,请查看:
https://github.com/Azure-Samples/data-catalog-bulk-import-glossary
数据目录仅包含委托权限。
但是,我尝试使用应用程序权限。因此,在我将其更改为基于用户登录(委托权限)后,它会抛出 Unauthorized。
现已修复。
感谢@Monica 和@Max 分享答案
我尝试 post Azure 数据目录中的 excel 数据。我是在控制台应用程序中编写的。
我的密码是
static void Main()
{
string DefaultCatalog = "DefaultCatalog";
string DefaultGlossary = "DefaultGlossary";
string fullUri = string.Format("https://api.azuredatacatalog.com/catalogs/{0}/glossaries/{1}/terms?api-version=2016-03-30",
DefaultCatalog, DefaultGlossary);
HttpWebRequest request = WebRequest.Create(fullUri) as HttpWebRequest;
request.KeepAlive = true;
request.Method = "GET";
request.Accept = "application/json;adc.metadata=full";
request.Headers.Add("Authorization", AccessToken().Result.CreateAuthorizationHeader());
request.AllowAutoRedirect = false;
HttpWebResponse response = request.GetResponse() as HttpWebResponse;
if (response != null && response.StatusCode == HttpStatusCode.Redirect)
{
using (var reader = new StreamReader(response.GetResponseStream()))
{
var itemPayload = reader.ReadToEnd();
JToken terms;
JObject.Parse(itemPayload).TryGetValue("value", out terms);
if (terms != null)
{
var r = JsonConvert.DeserializeObject<JArray>(terms.ToString());
}
}
}
}
static async Task<AuthenticationResult> AccessToken()
{
string clientId = "MyClientId";
string client_secret = "MyClientSecret";
string tenentId = "MytenentId";
if (_authResult == null)
{
// Resource Uri for Data Catalog API
string resourceUri = "https://api.azuredatacatalog.com/";
string redirectUri = "https://login.live.com/oauth20_desktop.srf";
string authorityUri = "https://login.windows.net/MytenentId/oauth2/authorize";
AuthenticationContext authContext = new AuthenticationContext(authorityUri);
_authResult = await authContext.AcquireTokenAsync(resourceUri, clientId, new Uri(redirectUri), new PlatformParameters(PromptBehavior.Always));
//ClientCredential cc = new ClientCredential(clientId, client_secret);
//_authResult = await authContext.AcquireTokenAsync(resourceUri, cc);
}
return _authResult;
}
我想从我的 azure datacatalog 中获取词汇表列表。但它总是返回未经授权的错误。 "The remote server returned an error: (403) Forbidden."
我的错误是
您需要使用来获取正确的令牌: 字符串 authorityUri = "https://login.windows.net/common/oauth2/authorize";
希望这对您有所帮助, 莫妮卡
确保您在词汇表管理员列表中。
此外,ADC 在 github 中也有很好的代码示例,可以满足您的需求,请查看: https://github.com/Azure-Samples/data-catalog-bulk-import-glossary
数据目录仅包含委托权限。 但是,我尝试使用应用程序权限。因此,在我将其更改为基于用户登录(委托权限)后,它会抛出 Unauthorized。
现已修复。
感谢@Monica 和@Max 分享答案