我想向我的应用程序添加一个特性,这样它就能够在没有用户交互的情况下将日历事件添加到outlook.com中。
我看到的所有示例都要求用户登录才能访问Office365API令牌。如何在没有用户交互的情况下获得该令牌?
发布于 2016-08-01 05:23:55
您可以使用客户端凭据来请求令牌,而不是使用OAuth 2.0代码授予流。
以下是供您参考的请求:
POST https://login.microsoftonline.com/<tenantId>/oauth2/token HTTP/1.1
Content-Type: application/x-www-form-urlencoded
grant_type=client_credentials
&client_id=<clientId>
&client_secret=<clientSecret>
&resource=https://outlook.office.com
下面是使用Microsoft.IdentityModel.Clients.ActiveDirectory
请求hte令牌的示例:
public static async Task<string> GetTokenAsync(string resource, string clientId, string secrect)
{
string authority = "https://login.microsoftonline.com/{yourTenantName}";
AuthenticationContext authContext = new AuthenticationContext(authority);
ClientCredential clientCredential = new ClientCredential(clientId, secrect);
AuthenticationResult authResult=await authContext.AcquireTokenAsync(resource, clientCredential);
return authResult.AccessToken;
}
有关Office365REST的详细信息,请参阅这里。
https://stackoverflow.com/questions/38646611
复制相似问题