Microsoft Graph API가 포함 된 webhook 프로젝트를 만들어 Office 365받은 편지함을 모니터링했습니다. Microsoft Graph API 구독 자동 업데이트
나는 단지 설명서에 따라로 3 일간을 갱신됩니다 UpdateSubscription 액션 메소드를 만든 다음https://graph.microsoft.io/en-us/docs/api-reference/v1.0/resources/subscription가 I'am 구독
를 업데이트하기 위해 HTTP 요청을 촉진하는 방법의 코드가에 제공 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)
};
'업데이트'버튼을 누르지 않고 자동으로 업데이트하는 방법이 있습니까?
인증 헤더에 사용자가 Office365 계정에 로그인해야하는 AuthResult.accessToken이 필요하기 때문에.
다음 메서드 GetAccessTokenFromRefreshTokenAsync를 사용하여 액세스 토큰을 가져 오는 데 사용되는 HttpRuntimeCache에서 'RefreshToken'을 검색하여 사용자의 구독을 업데이트 할 수있었습니다. 그러나 앱을 다시 시작하면 캐시에는 'RefreshToken'이 없습니다. 이것을 데이터베이스에 저장하는 것이 안전합니까? –