私はAzure Active DirectoryからMicrosoftのGraph API経由でユーザーのデータを読み取ろうとしています。グラフエクスプローラを使用する私はすべてのユーザーを取得できますが、スタンドアロンアプリケーションを使用すると、トークンを受け取った後に「承認されていない」応答が返されます。私は明らかにいくつかのステップを欠いていますが、それは私には明らかなステップではありません。Microsoft Graph Apiトークンが無効または承認されていませんか?
// config values
// authority = "https://login.microsoftonline.com/{ TENANT ID }/oauth2/"
// resource uri = "https:// APP NAME .azurewebsites.net";
// graph uri = https://graph.windows.net/TENANT ID/ also tried https://graph.windows.net/v1.0/
// short form
public async void GetUsers(ADConfiguration config)
{
_authContext = new AuthenticationContext(config.GetAuthority());
_clientCredential = new ClientCredential(config.ClientId, config.ClientSecret);
AuthenticationResult result = null;
// obtain the token, this part is still successful
result = await _authContext.AcquireTokenAsync(config.ResourceUri, _clientCredential);
_httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", result.AccessToken);
string address = config.GetGraphiUri() + "users?api-version=1.6";
// this response is always unauthorized
HttpResponseMessage response = await _httpClient.GetAsync(address);
}
感謝。提案は、エラーメッセージを「許可されていない」から「禁止された」に変更しました。私が推測している横方向の動き... 私は、リソースuriがAzureのADサーバーを参照すると信じています。いずれにしても、どちらのバリエーションもあまり成功していなかった。 – Mark
禁止されていることは、あなたのアプリに必要な権限がないことを意味します。 Azure AD Graphに追加したことを確認してください。 – juunas
「Windows Azure Active Directory」と「Microsoft Graph」という2つのAPIにはアクセス権があり、両方にすべての操作を行う権限があります。私はAPIアクセスを追加するために 'Azure AD Graph'を探しましたが、それはオプションとして出てこないのです。 – Mark