【发布时间】:2017-02-07 01:49:52
【问题描述】:
我已经使用 Microsoft Graph API 创建了 webhook 项目来监控 Office 365 收件箱。
根据https://graph.microsoft.io/en-us/docs/api-reference/v1.0/resources/subscription 上提供的文档,我创建了一个 UpdateSubscription 操作方法,仅将其更新 3 天
下面是我如何促进 HTTP 请求更新订阅的代码 sn-p
AuthenticationResult authResult = await AuthHelper.GetAccessTokenAsync();
HttpClient client = new HttpClient();
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", authResult.AccessToken);
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
// Build the request.
string subscriptionsEndpoint = "https://graph.microsoft.com/v1.0/subscriptions/"+id;
var method = new HttpMethod("PATCH");
HttpRequestMessage request = new HttpRequestMessage(method, subscriptionsEndpoint);
//get the current time
var subscription = new Subscription
{
//Id = id,
ExpirationDateTime = DateTime.UtcNow + new TimeSpan(0, 0, 4230, 0)
};
有没有一种无需用户按下“更新”按钮即可自动更新的方法?
因为授权标头需要 AuthResult.accessToken 这将要求用户登录到 Office365 帐户。
请指教
【问题讨论】:
-
我能够通过从 HttpRuntimeCache 中检索“RefreshToken”来更新用户的订阅,该 HttpRuntimeCache 用于使用以下方法 GetAccessTokenFromRefreshTokenAsync 获取访问令牌。但是,在执行应用程序重新启动时,缓存将没有“RefreshToken”。将其存储在数据库中是否安全
标签: asp.net-mvc asp.net-mvc-5 owin asp.net-webhooks