public ConfigBasedStoreInitializer(
            EntityFrameworkOptions options,
            ApplicationOptions appOptions,
            ILogger <ConfigBasedStoreInitializer> logger,
            MigrationDbContext migrationDbContext,
            IConfigurationDbContext configurationDbContext,
            IPersistedGrantDbContext persistedGrantDbContext,
            IUserAccountDbContext userAccountDbContext,
            IHostingEnvironment environment,
            IServiceProvider serviceProvider)
        {
            this._options                 = options;
            this._appOptions              = appOptions;
            this._logger                  = logger;
            this._migrationDbContext      = migrationDbContext;
            this._configurationDbContext  = configurationDbContext;
            this._persistedGrantDbContext = persistedGrantDbContext;
            this._userAccountDbContext    = userAccountDbContext;
            this._environment             = environment;

            this._serviceProvider = serviceProvider ??
                                    throw new ArgumentNullException(nameof(serviceProvider));

            this._logger.LogDebug("ConfigBasedStoreInitializer initialized");
        }
Exemplo n.º 2
0
 /// <summary>
 /// Creates a new instance of <see cref="DynamicScopePersistedGrantService{T}"/>.
 /// </summary>
 /// <param name="inner">Implements persisted grant logic.</param>
 /// <param name="persistedGrantDbContext">Abstraction for the operational data context.</param>
 /// <param name="dynamicScopeNotificationService">Contains methods to notify an API when a dynamic consent is altered.</param>
 /// <param name="serializer">Interface for persisted grant serialization.</param>
 public DynamicScopePersistedGrantService(T inner, IPersistedGrantDbContext persistedGrantDbContext, IDynamicScopeNotificationService dynamicScopeNotificationService, IPersistentGrantSerializer serializer)
 {
     _inner = inner;
     _persistedGrantDbContext         = persistedGrantDbContext ?? throw new ArgumentNullException(nameof(persistedGrantDbContext));
     _dynamicScopeNotificationService = dynamicScopeNotificationService ?? throw new ArgumentNullException(nameof(dynamicScopeNotificationService));
     _serializer = serializer ?? throw new ArgumentNullException(nameof(serializer));
 }
Exemplo n.º 3
0
        private Task RemoveDeviceCodes(IPersistedGrantDbContext context)
        {
            var found = Int32.MaxValue;

            while (found >= _options.TokenCleanupBatchSize)
            {
                var expiredCodes = context.DeviceFlowCodes
                                   .Where(x => x.Expiration < DateTime.UtcNow)
                                   .Take(_options.TokenCleanupBatchSize)
                                   .ToArray();

                found = expiredCodes.Length;
                _logger.LogInformation("Removing {deviceCodeCount} device flow codes", found);

                if (found > 0)
                {
                    context.DeviceFlowCodes.RemoveRange(expiredCodes);
                    try
                    {
                        context.SaveChanges();
                    }
                    catch (DbUpdateConcurrencyException ex)
                    {
                        // we get this if/when someone else already deleted the records
                        // we want to essentially ignore this, and keep working
                        _logger.LogDebug("Concurrency exception removing expired grants: {exception}", ex.Message);
                    }
                }
            }

            return(Task.CompletedTask);
        }
Exemplo n.º 4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PersistedGrantStore"/>
 /// class.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <param name="logger">The logger.</param>
 public PersistedGrantStore(
     IPersistedGrantDbContext context,
     ILogger <PersistedGrantStore> logger)
 {
     this._context = context;
     this._logger  = logger;
 }
Exemplo n.º 5
0
 public void ClearTokens()
 {
     try
     {
         _logger.LogTrace("Querying for tokens to clear", Array.Empty <object>());
         using (IServiceScope scope = _serviceProvider.GetRequiredService <IServiceScopeFactory>().CreateScope())
         {
             using (IPersistedGrantDbContext service = scope.ServiceProvider.GetService <IPersistedGrantDbContext>())
             {
                 PersistedGrant[] array = service.PersistedGrants.Where(x => x.Expiration < (DateTimeOffset?)DateTimeOffset.UtcNow).ToArray();
                 _logger.LogInformation("Clearing {tokenCount} tokens", (object)array.Length);
                 if (array.Length == 0)
                 {
                     return;
                 }
                 service.PersistedGrants.RemoveRange(array);
                 service.SaveChanges();
             }
         }
     }
     catch (Exception ex)
     {
         _logger.LogError("Exception clearing tokens: {exception}", (object)ex.Message);
     }
 }
Exemplo n.º 6
0
        public void ClearTokens()
        {
            this._logger.LogTrace("Querying for tokens to clear");

            using (IServiceScope serviceScope = this._serviceProvider
                                                .GetRequiredService <IServiceScopeFactory>().CreateScope())
            {
                using (IPersistedGrantDbContext context = serviceScope
                                                          .ServiceProvider.GetService <IPersistedGrantDbContext>())
                {
                    PersistedGrant[] expired = context.PersistedGrants
                                               .Where(x => x.Expiration < DateTimeOffset.UtcNow)
                                               .ToArray();

                    this._logger.LogInformation(
                        "Clearing {tokenCount} tokens",
                        expired.Length);

                    if (expired.Length > 0)
                    {
                        context.PersistedGrants.RemoveRange(expired);
                        context.SaveChanges();
                    }
                }
            }
        }
 public DeviceFlowStore(IPersistedGrantDbContext context,
                        IPersistentGrantSerializer serializer,
                        ILogger <DeviceFlowStore> logger)
 {
     _context    = context ?? throw new ArgumentNullException(nameof(context));
     _serializer = serializer ?? throw new ArgumentNullException(nameof(serializer));
     _logger     = logger ?? throw new ArgumentNullException(nameof(logger));
 }
        public PersistedGrantStore(IPersistedGrantDbContext context, ILogger <PersistedGrantStore> logger)
        {
            Guard.ForNull(context, nameof(context));
            Guard.ForNull(logger, nameof(logger));

            _context = context;
            _logger  = logger;
        }
 public PersistedGrantStore(
     IPersistedGrantDbContext context,
     ILogger <PersistedGrantStore> logger
     )
 {
     _repository = context;
     _logger     = logger;
 }
Exemplo n.º 10
0
 //  private readonly UserStore<ApplicationUser> _userStore;
 public UserController(UserManager <ApplicationUser> userManager, IConfigurationDbContext configDbContext,
                       IPersistedGrantDbContext persistedDbContext, RoleManager <ApplicationRole> roleMager)
 {
     _userManager        = userManager;
     _configDbContext    = configDbContext;
     _persistedDbContext = persistedDbContext;
     _roleMager          = roleMager;
 }
Exemplo n.º 11
0
 public PersistedGrantStore(
     IHttpContextAccessor contextAccessor,
     IPersistedGrantDbContext context, 
     ILogger<PersistedGrantStore> logger)
 {
     _contextAccessor = contextAccessor;
     _context = context;
     _logger = logger;
 }
Exemplo n.º 12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DeviceFlowStore"/> class.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <param name="serializer">The serializer</param>
 /// <param name="logger">The logger.</param>
 public DeviceFlowStore(
     IPersistedGrantDbContext context,
     IPersistentGrantSerializer serializer,
     ILogger <DeviceFlowStore> logger)
 {
     Context    = context;
     Serializer = serializer;
     Logger     = logger;
 }
Exemplo n.º 13
0
 public PersistedGrantStore(
     IHttpContextAccessor contextAccessor,
     IPersistedGrantDbContext context,
     ILogger <PersistedGrantStore> logger)
 {
     _contextAccessor = contextAccessor;
     _context         = context;
     _logger          = logger;
 }
Exemplo n.º 14
0
 /// <summary>
 /// Creates a new instance of <see cref="ParsedScopePersistedGrantService{T}"/>.
 /// </summary>
 /// <param name="inner">Implements persisted grant logic.</param>
 /// <param name="persistedGrantDbContext">Abstraction for the operational data context.</param>
 /// <param name="parsedScopeNotificationService">Contains methods to notify an API when a dynamic consent is altered.</param>
 /// <param name="serializer">Interface for persisted grant serialization.</param>
 /// <param name="scopeParser">Allows parsing raw scopes values into structured scope values.</param>
 public ParsedScopePersistedGrantService(TPersistedGrantService inner, IPersistedGrantDbContext persistedGrantDbContext, IParsedScopeNotificationService parsedScopeNotificationService, IPersistentGrantSerializer serializer,
                                         IScopeParser scopeParser)
 {
     _inner = inner;
     _persistedGrantDbContext        = persistedGrantDbContext ?? throw new ArgumentNullException(nameof(persistedGrantDbContext));
     _parsedScopeNotificationService = parsedScopeNotificationService ?? throw new ArgumentNullException(nameof(parsedScopeNotificationService));
     _serializer  = serializer ?? throw new ArgumentNullException(nameof(serializer));
     _scopeParser = scopeParser ?? throw new ArgumentNullException(nameof(scopeParser));
 }
 public PersistedGrantStore(
     SiteContext site,
     IPersistedGrantDbContext context,
     ILogger <PersistedGrantStore> logger)
 {
     _siteId  = site.Id.ToString();
     _context = context;
     _logger  = logger;
 }
        public OidcConfigurationController(
            IClientRequestParametersProvider clientRequestParametersProvider,
            ILogger <OidcConfigurationController> _logger,
            IPersistedGrantDbContext context)
        {
            ClientRequestParametersProvider = clientRequestParametersProvider;
            logger = _logger;

            var list = context.PersistedGrants.ToList();
        }
Exemplo n.º 17
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DeviceFlowStore"/> class.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <param name="serializer">The serializer</param>
 /// <param name="logger">The logger.</param>
 /// <param name="cancellationTokenProvider"></param>
 public DeviceFlowStore(
     IPersistedGrantDbContext context,
     IPersistentGrantSerializer serializer,
     ILogger <DeviceFlowStore> logger,
     ICancellationTokenProvider cancellationTokenProvider)
 {
     Context    = context;
     Serializer = serializer;
     Logger     = logger;
     CancellationTokenProvider = cancellationTokenProvider;
 }
Exemplo n.º 18
0
 public DeviceFlowStore(
     IHttpContextAccessor contextAccessor,
     IPersistedGrantDbContext context,
     IPersistentGrantSerializer serializer,
     ILogger <DeviceFlowStore> logger
     )
 {
     _contextAccessor = contextAccessor;
     _context         = context;
     _serializer      = serializer;
     _logger          = logger;
 }
Exemplo n.º 19
0
 public PersistedGrantStore(IPersistedGrantDbContext context, ILogger <PersistedGrantStore> logger)
 {
     if (context == null)
     {
         throw new ArgumentNullException(nameof(context));
     }
     if (logger == null)
     {
         throw new ArgumentNullException(nameof(logger));
     }
     _context = context;
     _logger  = logger;
 }
Exemplo n.º 20
0
 public DefaultStoreInitializer(
     EntityFrameworkOptions options,
     ILogger <DefaultStoreInitializer> logger,
     DefaultDbContext defaultDbContext,
     IConfigurationDbContext configurationDbContext,
     IPersistedGrantDbContext persistedGrantDbContext,
     IUserAccountDbContext userAccountDbContext)
 {
     _options                 = options;
     _logger                  = logger;
     _defaultDbContext        = defaultDbContext;
     _configurationDbContext  = configurationDbContext;
     _persistedGrantDbContext = persistedGrantDbContext;
     _userAccountDbContext    = userAccountDbContext;
 }
Exemplo n.º 21
0
        /// <summary>
        /// Constructor for TokenCleanupService.
        /// </summary>
        /// <param name="options"></param>
        /// <param name="persistedGrantDbContext"></param>
        /// <param name="operationalStoreNotification"></param>
        /// <param name="logger"></param>
        public TokenCleanupService(
            OperationalStoreOptions options,
            IPersistedGrantDbContext persistedGrantDbContext,
            ILogger <TokenCleanupService> logger,
            IOperationalStoreNotification operationalStoreNotification = null)
        {
            _options = options ?? throw new ArgumentNullException(nameof(options));
            if (_options.TokenCleanupBatchSize < 1)
            {
                throw new ArgumentException("Token cleanup batch size interval must be at least 1");
            }

            _persistedGrantDbContext = persistedGrantDbContext ?? throw new ArgumentNullException(nameof(persistedGrantDbContext));
            _logger = logger ?? throw new ArgumentNullException(nameof(logger));

            _operationalStoreNotification = operationalStoreNotification;
        }
 public ExampleDataStoreInitializer(
     EntityFrameworkOptions options,
     ApplicationOptions appOptions,
     ILogger <ConfigBasedStoreInitializer> logger,
     MigrationDbContext migrationDbContext,
     IConfigurationDbContext configurationDbContext,
     IPersistedGrantDbContext persistedGrantDbContext,
     IUserAccountDbContext userAccountDbContext,
     ICrypto crypto)
 {
     this.options                 = options;
     this.appOptions              = appOptions;
     this.logger                  = logger;
     this.migrationDbContext      = migrationDbContext;
     this.configurationDbContext  = configurationDbContext;
     this.persistedGrantDbContext = persistedGrantDbContext;
     this.userAccountDbContext    = userAccountDbContext;
     this.crypto                  = crypto;
 }
Exemplo n.º 23
0
        private async Task RemoveGrants(IPersistedGrantDbContext context, IOperationalStoreNotification tokenCleanupNotification)
        {
            var found = Int32.MaxValue;

            while (found >= _options.TokenCleanupBatchSize)
            {
                var expiredGrants = context.PersistedGrants
                                    .Where(x => x.Expiration < DateTime.UtcNow)
                                    .OrderBy(x => x.Key)
                                    .Take(_options.TokenCleanupBatchSize)
                                    .ToArray();

                found = expiredGrants.Length;
                _logger.LogInformation("Removing {grantCount} grants", found);

                if (found > 0)
                {
                    context.PersistedGrants.RemoveRange(expiredGrants);
                    try
                    {
                        context.SaveChanges();

                        if (tokenCleanupNotification != null)
                        {
                            await tokenCleanupNotification.PersistedGrantsRemovedAsync(expiredGrants);
                        }
                    }
                    catch (DbUpdateConcurrencyException ex)
                    {
                        // we get this if/when someone else already deleted the records
                        // we want to essentially ignore this, and keep working
                        _logger.LogDebug("Concurrency exception removing expired grants: {exception}", ex.Message);
                    }
                }
            }
        }
Exemplo n.º 24
0
    /// <summary>
    /// Saves changes and handles concurrency exceptions.
    /// </summary>
    public static async Task <ICollection <T> > SaveChangesWithConcurrencyCheckAsync <T>(this IPersistedGrantDbContext context, ILogger logger, CancellationToken cancellationToken = default)
        where T : class
    {
        var list = new List <T>();

        var count = 3;

        while (count > 0)
        {
            try
            {
                await context.SaveChangesAsync(cancellationToken);

                return(list);
            }
            catch (DbUpdateConcurrencyException ex)
            {
                count--;

                // we get this if/when someone else already deleted the records
                // we want to essentially ignore this, and keep working
                logger.LogDebug("Concurrency exception removing records: {exception}", ex.Message);

                foreach (var entry in ex.Entries)
                {
                    // mark this entry as not attached anymore so we don't try to re-delete
                    entry.State = EntityState.Detached;
                    list.Add((T)entry.Entity);
                }
            }
        }

        logger.LogDebug("Too many concurrency exceptions. Exiting.");

        return(list);
    }
 /// <summary>
 /// Initializes a new instance of the <see cref="PersistedGrantStore"/> class.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <param name="logger">The logger.</param>
 /// <param name="cancellationTokenProvider"></param>
 public PersistedGrantStore(IPersistedGrantDbContext context, ILogger <PersistedGrantStore> logger, ICancellationTokenProvider cancellationTokenProvider)
 {
     Context = context;
     Logger  = logger;
     CancellationTokenProvider = cancellationTokenProvider;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="SigningKeyStore"/> class.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <param name="logger">The logger.</param>
 /// <exception cref="ArgumentNullException">context</exception>
 public SigningKeyStore(IPersistedGrantDbContext context, ILogger <SigningKeyStore> logger)
 {
     Context = context ?? throw new ArgumentNullException(nameof(context));
     Logger  = logger;
 }
Exemplo n.º 27
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ServerSideSessionStore"/> class.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <param name="logger">The logger.</param>
 /// <param name="cancellationTokenProvider"></param>
 /// <exception cref="ArgumentNullException">context</exception>
 public ServerSideSessionStore(IPersistedGrantDbContext context, ILogger <ServerSideSessionStore> logger, ICancellationTokenProvider cancellationTokenProvider)
 {
     Context = context ?? throw new ArgumentNullException(nameof(context));
     Logger  = logger;
     CancellationTokenProvider = cancellationTokenProvider;
 }
Exemplo n.º 28
0
 public PersistedGrantRepository(IPersistedGrantDbContext context)
 {
     this.DbSet = context.PersistedGrants;
 }
Exemplo n.º 29
0
 public DeleteModel(IPersistedGrantDbContext context)
 {
     _context = context;
 }
Exemplo n.º 30
0
 public PersistedGrantStore(IPersistedGrantDbContext context, AppDbContext appContext, ILogger <PersistedGrantStore> logger)
 {
     _context    = context;
     _logger     = logger;
     _appContext = appContext;
 }
Exemplo n.º 31
0
 public IndexModel(IPersistedGrantDbContext context)
 {
     _context = context;
 }