public static async Task <Subscription> GetSubscriptionAsync(this GraphServiceClient service, string graphAccessToken, string subscriptionId) { Subscription subscription = null; try { SubscriptionRequestBuilder builder = new SubscriptionRequestBuilder(string.Format("{0}subscriptions/{1}", AADAppSettings.GraphResourceUrl, subscriptionId), new BaseClient(AADAppSettings.GraphResourceUrl, new DelegateAuthenticationProvider( (requestMessage) => { requestMessage.Headers.Authorization = new AuthenticationHeaderValue("bearer", graphAccessToken); requestMessage.Method = HttpMethod.Get; requestMessage.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); return(Task.FromResult(0)); }))); subscription = await builder.Request().GetAsync(); } catch { } return(subscription); }
public static async Task <Subscription> CreateSubscriptionAsync(this GraphServiceClient service, string graphAccessToken) { Subscription subscription = new Subscription() { ChangeType = "created,updated", ClientState = Guid.NewGuid().ToString(), //https://graph.microsoft.io/en-us/docs/api-reference/v1.0/resources/subscription ExpirationDateTime = DateTime.UtcNow + new TimeSpan(0, 2, 0, 0),//TimeSpan.FromMinutes(4230),// NotificationUrl = ConfigurationManager.AppSettings["NotificationUrl"], Resource = "me/mailFolders('Inbox')/messages" }; int retrycount = 5; while (retrycount-- > 0) { try { SubscriptionRequestBuilder builder = new SubscriptionRequestBuilder(string.Format("{0}subscriptions", AADAppSettings.GraphResourceUrl), new BaseClient(AADAppSettings.GraphResourceUrl, new DelegateAuthenticationProvider( (requestMessage) => { requestMessage.Headers.Authorization = new AuthenticationHeaderValue("bearer", graphAccessToken); requestMessage.Method = HttpMethod.Post; requestMessage.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); return(Task.FromResult(0)); }))); subscription = await builder.Request().CreateAsync(subscription); break; } catch { } } return(subscription.Id != null ? subscription : null); }
public static async Task<Subscription> CreateSubscriptionAsync(this GraphServiceClient service, string graphAccessToken) { Subscription subscription = new Subscription() { ChangeType = "created,updated", ClientState = Guid.NewGuid().ToString(), //https://graph.microsoft.io/en-us/docs/api-reference/v1.0/resources/subscription ExpirationDateTime = DateTime.UtcNow + new TimeSpan(0, 2, 0, 0),//TimeSpan.FromMinutes(4230),// NotificationUrl = ConfigurationManager.AppSettings["NotificationUrl"], Resource = "me/mailFolders('Inbox')/messages" }; int retrycount = 5; while (retrycount-- > 0) { try { SubscriptionRequestBuilder builder = new SubscriptionRequestBuilder(string.Format("{0}subscriptions", AADAppSettings.GraphResourceUrl), new BaseClient(AADAppSettings.GraphResourceUrl, new DelegateAuthenticationProvider( (requestMessage) => { requestMessage.Headers.Authorization = new AuthenticationHeaderValue("bearer", graphAccessToken); requestMessage.Method = HttpMethod.Post; requestMessage.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); return Task.FromResult(0); }))); subscription = await builder.Request().CreateAsync(subscription); break; } catch { } } return subscription.Id != null ? subscription : null; }
public static async Task<Subscription> GetSubscriptionAsync(this GraphServiceClient service, string graphAccessToken, string subscriptionId) { Subscription subscription = null; try { SubscriptionRequestBuilder builder = new SubscriptionRequestBuilder(string.Format("{0}subscriptions/{1}", AADAppSettings.GraphResourceUrl, subscriptionId), new BaseClient(AADAppSettings.GraphResourceUrl, new DelegateAuthenticationProvider( (requestMessage) => { requestMessage.Headers.Authorization = new AuthenticationHeaderValue("bearer", graphAccessToken); requestMessage.Method = HttpMethod.Get; requestMessage.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); return Task.FromResult(0); }))); subscription = await builder.Request().GetAsync(); } catch { } return subscription; }