Validation 授权请求被拒绝:权限不足,无法完成操作。”;应用程序错误,仅在第三方广告上

Validation 授权请求被拒绝:权限不足,无法完成操作。”;应用程序错误,仅在第三方广告上,validation,oauth-2.0,azure-active-directory,microsoft-graph-api,adal,Validation,Oauth 2.0,Azure Active Directory,Microsoft Graph Api,Adal,我正在尝试通过应用程序访问流在我自己和第三方Azure Active Directoriy中搜索用户。 我使用以下命令获取有效令牌 string authority = string.Format(CultureInfo.InvariantCulture, "https://login.microsoftonline.com/{0}", "<AD>.onmicrosoft.com"); AuthenticationContext authContext = new Authentic

我正在尝试通过应用程序访问流在我自己和第三方Azure Active Directoriy中搜索用户。 我使用以下命令获取有效令牌

string authority = string.Format(CultureInfo.InvariantCulture, "https://login.microsoftonline.com/{0}", "<AD>.onmicrosoft.com");
AuthenticationContext authContext = new AuthenticationContext(authority);
ClientCredential clientCredential = new ClientCredential(<clientId>, <appKey>);

AuthenticationResult result = await authContext.AcquireTokenAsync("https://graph.windows.net" , clientCredential);
string TokenForApplication = result.AccessToken;

我保持其他一切不变。

从您的屏幕截图中,所选权限是针对Microsoft Graph API(),但根据您的代码,您正在获取Azure AD Graph API()的令牌

如果您想使用Azure AD Graph api,您应该在多租户应用程序的
必需权限
刀片中添加对
Windows Azure Active Directory
的权限,并在其他AAD中进行管理员同意


如果要使用Microsoft Graph API,应修改代码,使用
https://graph.microsoft.com
而不是
https://graph.windows.net

从您的屏幕截图中,所选权限适用于Microsoft Graph API(),但根据您的代码,您正在获取Azure AD Graph API()的令牌

如果您想使用Azure AD Graph api,您应该在多租户应用程序的
必需权限
刀片中添加对
Windows Azure Active Directory
的权限,并在其他AAD中进行管理员同意


如果要使用Microsoft Graph API,应修改代码,使用
https://graph.microsoft.com
而不是
https://graph.windows.net

谢谢,我没有意识到我实际上在使用Azure AD Graph API!如果我更改端点,我会得到“BadRequest”:“Invalid version”,我收集到的信息表明我需要更改代码以使用不同的调用集?您想使用Azure AD Graph API或microsoft Graph API吗?您的sdk似乎正在使用azure ad graph api。是的,我从您的回答中了解到我当前正在使用azure ad graph api。我想使用Microsoft graph API。好的,那么您需要制作。microsoft graph提供了.net sdk,您可以查看其中的代码示例,尤其是。谢谢,我没有意识到我实际上在使用Azure AD graph API!如果我更改端点,我会得到“BadRequest”:“Invalid version”,我收集到的信息表明我需要更改代码以使用不同的调用集?您想使用Azure AD Graph API或microsoft Graph API吗?您的sdk似乎正在使用azure ad graph api。是的,我从您的回答中了解到我当前正在使用azure ad graph api。我想使用Microsoft graph API。好的,那么您需要制作。而MicrosoftGraph提供了.NETSDK,您可以查看其中的代码示例,尤其是。
public async Task<List<IUser>> UsersSearch(IActiveDirectoryClient client, string searchString)
{
    List<IUser> usersList = null;
    IPagedCollection<IUser> searchResults = null;

    IUserCollection userCollection = client.Users;
    searchResults = await userCollection.Where(user =>
        user.UserPrincipalName.StartsWith(searchString) ||
        user.GivenName.StartsWith(searchString)).Take(10).ExecuteAsync();
    usersList = searchResults.CurrentPage.ToList();

    return usersList;
}
string authority = string.Format(CultureInfo.InvariantCulture, "https://login.microsoftonline.com/{0}", "<AD>.onmicrosoft.com");