2017-04-02 245 views
1

我有一个后台应用程序应该连接到数据目录并获取与表有关的信息。由于它是一个后台应用程序,我不能有任何用户干预来验证数据目录请求。所以我尝试使用ClientID和ClientSecret进行身份验证。基于应用程序令牌的请求返回不是401未授权

string authorityUri = "https://login.microsoftonline.com/{adtenanthere}"; 

string resourceUri = "https://datacatalog.azure.com"; 

string clientId = "{clientidhere}"; 

string clientSecret = "{clientsecrethere}"; 

AuthenticationContext authContext1 = new AuthenticationContext(authorityUri, false); 

ClientCredential credential = new ClientCredential(clientId, clientSecret); 

AuthenticationResult authResult = authContext1.AcquireTokenAsync(resourceUri, credential).Result; 

string token = authResult.CreateAuthorizationHeader(); 

获得使用这种方法是成功的,但是当我使用此标记为数据目录API请求,请求返回“401令牌 - 未经授权:访问由于凭据无效被拒绝你不必使用您提供的凭据查看此目录或页面的权限“。

请建议我可能在这里失踪!

回答

0

首先检查Azure的广告权限您的应用程序许可。我在Application Azure数据目录中检查没有权限。因此,您必须使用用户凭据进行访问。请参阅图像

应用程序权限基于客户端凭据。代表 基于登录用户权限的权限。

您应该不需要登录弹出窗口,您必须直接传递 中的用户凭证 。

enter image description here

enter image description here

因此,更改和检查,你不会得到401未经授权

我认为这是对你的帮助。

+0

莫妮卡给予权威url和资源url也检查一个它是一个正确的值 – umasankar