我在尝试使用Microsoft Graph API时遇到以下异常,我不确定我做错了什么:
“无法建立调用应用程序的身份。”
通过令牌的初始身份验证似乎没有错误
public class AzureAuthenticationProvider : IAuthenticationProvider
{
public async Task AuthenticateRequestAsync(HttpRequestMessage request)
{
string clientId = "xxxxx";
string clientSecret = "yyyyyy";
string tenant = config.AzureUat.UserName.Split('@')[1];
AuthenticationContext authContext = new AuthenticationContext("https://login.windows.net/" + tenant + "/oauth2/token");
ClientCredential creds = new ClientCredential(clientId, clientSecret);
AuthenticationResult authResult = await authContext.AcquireTokenAsync("https://graph.microsoft.com/", creds);
request.Headers.Add("Authorization", "Bearer " + authResult.AccessToken);
}
}
然后我加载GraphServiceClient,这似乎也可以正常工作
GraphServiceClient graphClient = new GraphServiceClient(new AzureAuthenticationProvider());
这是代码获取身份验证失败的地方:
var groups = await graphClient.Groups.Request().GetAsync();
任何帮助都将非常感谢!!!