示例#1
0
        public static async Task DeleteSubscriptionAsync(this GraphServiceClient service, string graphAccessToken, string subscriptionId)
        {
            try
            {
                var accessToken = await AuthenticationHelper.GetGraphAccessTokenAsync();

                SubscriptionRequestBuilder builder = new Microsoft.Graph.SubscriptionRequestBuilder(string.Format("{0}subscriptions/{1}", AADAppSettings.GraphResourceUrl, subscriptionId), new Microsoft.Graph.BaseClient(AADAppSettings.GraphResourceUrl,
                                                                                                                                                                                                                           new DelegateAuthenticationProvider(
                                                                                                                                                                                                                               (requestMessage) =>
                {
                    requestMessage.Headers.Authorization = new AuthenticationHeaderValue("bearer", accessToken);
                    requestMessage.Method = HttpMethod.Delete;
                    requestMessage.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                    return(Task.FromResult(0));
                })));

                await builder.Request().DeleteAsync();

                return;
            }
            catch (Exception ex)
            {
                //throw ex;
            }
        }
        public static async Task DeleteSubscriptionAsync(this GraphServiceClient service, string graphAccessToken, string subscriptionId)
        {
            try
            {
                var accessToken = await AuthenticationHelper.GetGraphAccessTokenAsync();
                SubscriptionRequestBuilder builder = new Microsoft.Graph.SubscriptionRequestBuilder(string.Format("{0}subscriptions/{1}", AADAppSettings.GraphResourceUrl, subscriptionId), new Microsoft.Graph.BaseClient(AADAppSettings.GraphResourceUrl,
                                                                        new DelegateAuthenticationProvider(
                                                                            (requestMessage) =>
                                                                            {
                                                                                requestMessage.Headers.Authorization = new AuthenticationHeaderValue("bearer", accessToken);
                                                                                requestMessage.Method = HttpMethod.Delete;
                                                                                requestMessage.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                                                                                return Task.FromResult(0);
                                                                            })));

                await builder.Request().DeleteAsync();
                return;
            }
            catch (Exception ex)
            {
                //throw ex;
            }

        }