[英]Office 365 APIs Microsoft Graph authentication failed
I registered sample app from Microsoft graph sample app 我从Microsoft graph示例应用程序注册了示例应用程序
And standard login is working but when I try to make it simplier by using this code: 标准登录正在工作,但是当我尝试使用以下代码使其更简单时:
var authContext = new AuthenticationContext(Settings.AzureADAuthority);
var token = authContext.AcquireToken(Settings.O365UnifiedAPIResource, new ClientCredential(Settings.ClientId, Settings.ClientSecret)).AccessToken;
I get the following error: Application with identifier '[ClientId here]' was not found in the directory microsoft.com
我收到以下错误:
Application with identifier '[ClientId here]' was not found in the directory microsoft.com
Setting.O365UnifiedAPIResource = @"https://graph.microsoft.com/";
Settings.AzureADAuthority = @"https://login.microsoftonline.com/common";
Does anyone know what can be the problem? 有谁知道可能是什么问题?
Settings.AzureADAuthority = @"https://login.microsoftonline.com/{tenant_id or tenant_name}";
When acquiring the token by using the client credential (client id + client secret). 通过使用客户端证书(客户端ID +客户端密钥)获取令牌时。 You should specify the tenant explicitly.
您应该明确指定承租人。
For example: 例如:
https://login.microsoftonline.com/ {tenant_id} https://login.microsoftonline.com/ {tenant_id}
or 要么
https://login.microsoftonline.com/ {your_domain.onmicrosoft.com} https://login.microsoftonline.com/ {your_domain.onmicrosoft.com}
BTW, as this registration will be for the sample app, it will only have the Mail.Send permission which is delegated permission. 顺便说一句,因为此注册将针对示例应用程序,所以它将仅具有Mail.Send权限(即委派权限)。 To acquire the app token, you also need to grant the app level permission in Azure AD since your are acquiring the app token rather than the user token.
若要获取应用程序令牌,还需要在Azure AD中授予应用程序级别权限,因为您是在获取应用程序令牌而不是用户令牌。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.