AADアカウントを使用してMS Graphにアクセスしようとしていますが、このアカウントはグローバル管理者であり、あらゆる権限が委任されています。インタラクティブなログインなしで、つまりUserPasswordCredential
を使用してやりたいアクセストークンの妥当性検査エラーUserCredentialsを使用したMSのグラフ
私の流れ:
は、トークンの取得:MSグラフにアクセスしようとすると、私はエラーを取得する
public async Task<string> GetUserAccessTokenAsync()
{
UserPasswordCredential userPasswordCredential = new UserPasswordCredential("[email protected]", "password");
AuthenticationContext authContext = new AuthenticationContext("https://login.microsoftonline.com/tenant.onmicrosoft.com");
AuthenticationResult token = await authContext.AcquireTokenAsync("https://graph.windows.net", appId, userPasswordCredential);
return token.AccessToken;
}
トークン使用:
public static GraphServiceClient GetAuthenticatedClient()
{
GraphServiceClient graphClient = new GraphServiceClient(
new DelegateAuthenticationProvider(
async (requestMessage) =>
{
Adal adal = new Adal();
string accessToken = await adal.GetUserAccessTokenAsync();
// Append the access token to the request.
requestMessage.Headers.Authorization = new AuthenticationHeaderValue("bearer", accessToken);
}));
return graphClient;
}
を呼び出そうとしイベントを読むためのMSグラフ:
try
{
// Get events.
items = await eventsService.GetMyEvents(graphClient);
}
catch (ServiceException se)
{
//this is where I get the error
}
任意のアイデア私が間違っているつもりですか?
lord ...時には自分自身も驚いています。ありがとうございました。 –
コード例でリソースURIを入力しましたが、修正されました。 – juunas