internal static async Task <Subscription> CreateSubscription(string baseUrl, string userId = null)
        {
            var graphClient = GraphHelper.GetAuthenticatedClient(string.IsNullOrEmpty(userId) ? CurrentUserId : userId, baseUrl);

            var subscription = new Subscription
            {
                Resource           = "me/mailFolders('Inbox')/messages",
                ChangeType         = "created",
                NotificationUrl    = ConfigurationManager.AppSettings["ida:NotificationUrl"],
                ClientState        = Guid.NewGuid().ToString(),
                ExpirationDateTime = DateTime.UtcNow + new TimeSpan(0, 0, 15, 0) // shorter duration useful for testing
            };

            var newSubscription = await graphClient.Subscriptions.Request().AddAsync(subscription);

            // This sample temporarily stores the current subscription ID, client state, and user object ID.
            // This info is required so the NotificationController, which is not authenticated, can retrieve
            // an access token from the cache and validate the subscription.
            // Production apps typically use some method of persistent storage.
            var subscriptionDetails = new SubscriptionDetails(
                newSubscription.Id,
                newSubscription.ClientState,
                CurrentUserId,
                baseUrl);

            SubscriptionCache.GetSubscriptionCache().SaveSubscriptionInfo(subscriptionDetails);

            return(newSubscription);
        }
        // This sample temporarily stores the current subscription ID, client state, user object ID, and tenant ID.
        // This info is required so the NotificationController can retrieve an access token from the cache and validate the subscription.
        // Production apps typically use some method of persistent storage.
        public void SaveSubscriptionInfo(SubscriptionDetails subscriptionDetails)
        {
            if (objCache["subscription_store"] == null)
            {
                var subscriptionstore = new Dictionary <string, SubscriptionDetails>();
                subscriptionstore.Add(subscriptionDetails.SubscriptionId, subscriptionDetails);

                objCache.Set(new CacheItem("subscription_store", subscriptionstore), defaultPolicy);
            }
            else
            {
                var subscriptionstore = objCache.Get("subscription_store") as Dictionary <string, SubscriptionDetails>;
                subscriptionstore.Add(subscriptionDetails.SubscriptionId, subscriptionDetails);
            }
        }