コード例 #1
0
        /// <summary>
        /// Removes the stale persisted grants.
        /// </summary>
        /// <returns></returns>
        protected virtual async Task RemoveGrantsAsync()
        {
            try
            {
                var found = 0;

                do
                {
                    var collection = (await _persistedGrantStore.GetExpiredGrantsAsync(_options.TokenCleanupBatchSize))
                                     .ToArray()
                    ;

                    found = collection.Length;
                    if (found > 0)
                    {
                        _logger.LogInformation("Removing {grantCount} grants", found);
                        if (_operationalStoreNotification != null)
                        {
                            await _operationalStoreNotification.PersistedGrantsRemoveAsync(collection);
                        }

                        foreach (var persistedGrant in collection)
                        {
                            await _persistedGrantStore.DeleteAsync(persistedGrant);
                        }
                    }
                } while (found > 0);
            }
            catch (Exception ex)
            {
                if (!HandleConcurrencyException(ex))
                {
                    throw;
                }
            }
        }