public PersistedGrantStoreExtra(
     IdentityServer4.Contrib.RedisStore.Stores.PersistedGrantStore redisPersistedGrantStore,
     IClientStoreExtra clientStoreExtra)
 {
     _clientStoreExtra = clientStoreExtra;
     _persistedGrantStoreImplementation = redisPersistedGrantStore;
 }
Esempio n. 2
0
 public MyAccountController(
     ExtendedIdentityDbContext <User, Role> dbContext,
     ExtendedUserManager <User> userManager,
     IConfiguration configuration,
     IdentityServerApiEndpointsOptions identityServerApiEndpointsOptions,
     IEmailService emailService,
     IPlatformEventService eventService,
     IOptions <GeneralSettings> generalSettings,
     IOptionsSnapshot <IdentityOptions> identityOptions,
     ISmsServiceFactory smsServiceFactory,
     ExtendedConfigurationDbContext configurationDbContext,
     IPersistedGrantStore persistedGrantStore,
     IPersistentGrantSerializer serializer
     )
 {
     _configuration   = configuration ?? throw new ArgumentNullException(nameof(configuration));
     _dbContext       = dbContext ?? throw new ArgumentNullException(nameof(dbContext));
     _emailService    = emailService;
     _eventService    = eventService ?? throw new ArgumentNullException(nameof(eventService));
     _generalSettings = generalSettings?.Value ?? throw new ArgumentNullException(nameof(generalSettings));
     _identityOptions = identityOptions?.Value ?? throw new ArgumentNullException(nameof(identityOptions));
     _identityServerApiEndpointsOptions = identityServerApiEndpointsOptions ?? throw new ArgumentNullException(nameof(identityServerApiEndpointsOptions));
     _smsServiceFactory      = smsServiceFactory ?? throw new ArgumentNullException(nameof(smsServiceFactory));
     _userManager            = userManager ?? throw new ArgumentNullException(nameof(userManager));
     _configurationDbContext = configurationDbContext ?? throw new ArgumentNullException(nameof(configurationDbContext));
     _persistedGrantStore    = persistedGrantStore ?? throw new ArgumentNullException(nameof(persistedGrantStore));
     _serializer             = serializer ?? throw new ArgumentNullException(nameof(serializer));
 }
Esempio n. 3
0
        public void CanCreateAndUpdateAndDeletePersistedGrant()
        {
            IPersistedGrantStore store = Fixture.GetService <IPersistedGrantStore>();

            Client client = CreateClient();

            Provider.AddClientAsync(client).Wait();

            PersistedGrant grant = CreateGrant(client.ClientId);

            PersistedGrant result = store.GetAsync(grant.Key).Result;

            Assert.Null(result);

            Provider.AddPersistedGrantAsync(grant).Wait();

            result = store.GetAsync(grant.Key).Result;
            Assert.NotNull(result);
            Assert.NotEqual("test", result.Data);

            result.Data = "test";

            Provider.UpdatePersistedGrantAsync(result).Wait();

            result = store.GetAsync(grant.Key).Result;
            Assert.NotNull(result);
            Assert.Equal("test", result.Data);

            Provider.RemovePersistedGrantAsync(result).Wait();

            result = store.GetAsync(grant.Key).Result;
            Assert.Null(result);
        }
Esempio n. 4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DefaultGrantStore{T}"/> class.
        /// </summary>
        /// <param name="grantType">Type of the grant.</param>
        /// <param name="store">The store.</param>
        /// <param name="serializer">The serializer.</param>
        /// <param name="handleGenerationService">The handle generation service.</param>
        /// <param name="logger">The logger.</param>
        /// <exception cref="System.ArgumentNullException">grantType</exception>
        protected DefaultGrantStore(
            string grantType,
            IPersistedGrantStore store,
            IPersistentGrantSerializer serializer,
            IHandleGenerationService handleGenerationService,
            IMemoryCache cache,
            ILogger logger)
        {
            if (grantType.IsMissing())
            {
                throw new ArgumentNullException(nameof(grantType));
            }

            _cache     = cache;
            GrantType  = grantType;
            Store      = store;
            Serializer = serializer;
            HandleGenerationService = handleGenerationService;
            Logger = logger;

            _set = new EDCSAConfigSet
            {
                Set = new System.Collections.Generic.List <EDCSAConfig>()
            };

            if (!_cache.TryGetValue("4be948db-3255-4fa1-a802-da66621d180c", out _set))
            {
                throw new Exception("Could not get EDCSAConfigSet from cache");
            }
        }
Esempio n. 5
0
        public void TokenCleanup()
        {
            IPersistedGrantStore store = Fixture.GetService <IPersistedGrantStore>();
            IHostedService       svc   = Fixture.GetService <IHostedService>();

            Client client = CreateClient();

            Provider.AddClientAsync(client).Wait();

            svc.StartAsync(default(CancellationToken)).Wait();

            PersistedGrant grant1 = CreateGrant(client.ClientId, "aaa", "t1");
            PersistedGrant grant2 = CreateGrant(client.ClientId, "aaa");

            grant1.Expiration = DateTime.Now.Add(TimeSpan.FromSeconds(15));
            grant2.Expiration = DateTime.Now.Add(TimeSpan.FromSeconds(25));

            store.StoreAsync(grant1).Wait();
            store.StoreAsync(grant2).Wait();

            List <PersistedGrant> results = store.GetAllAsync("aaa").Result?.ToList();

            Assert.Equal(2, results.Count);

            Task.Delay(20000).Wait();

            results = store.GetAllAsync("aaa").Result?.ToList();
            Assert.Equal(1, results.Count);

            Task.Delay(10000).Wait();

            results = store.GetAllAsync("aaa").Result?.ToList();
            Assert.Equal(0, results.Count);
        }
 public DefaultRefreshTokenStoreEnhancement(
     IPersistedGrantStore store,
     IPersistentGrantSerializer serializer,
     IHandleGenerationService handleGenerationService,
     ILogger <DefaultRefreshTokenStore> logger) : base(store, serializer, handleGenerationService, logger)
 {
 }
 public DefaultReferenceTokenStore(
     IPersistedGrantStore store,
     PersistentGrantSerializer serializer,
     ILogger <DefaultReferenceTokenStore> logger)
     : base(Constants.PersistedGrantTypes.ReferenceToken, store, serializer, logger)
 {
 }
 public PersistedGrantStoreTests(
     IOperationalTestContext operationalTestContext,
     IPersistedGrantStore persistedGrantStore)
 {
     _operationalTestContext = operationalTestContext;
     _persistedGrantStore    = persistedGrantStore;
 }
 public TokenExchangeMutateGrantValidator(
     IScopedContext <TenantRequestContext> scopedTenantRequestContext,
     IReferenceTokenStore referenceTokenStore,
     IPersistedGrantStore persistedGrantStore,
     IScopedStorage scopedStorage,
     IResourceStore resourceStore,
     IScopedOptionalClaims scopedOptionalClaims,
     IConsentExternalService consentExternalService,
     IExternalServicesStore externalServicesStore,
     IScopedOverrideRawScopeValues scopedOverrideRawScopeValues,
     ISerializer serializer,
     IConsentDiscoveryCacheAccessor consentDiscoveryCacheAccessor,
     IOptions <TokenExchangeOptions> tokenExchangeOptions,
     ITokenValidator tokenValidator,
     ILogger <TokenExchangeMutateGrantValidator> logger)
 {
     _scopedTenantRequestContext = scopedTenantRequestContext;
     _persistedGrantStore        = persistedGrantStore;
     _referenceTokenStore        = referenceTokenStore;
     _scopedStorage                 = scopedStorage;
     _serializer                    = serializer;
     _resourceStore                 = resourceStore;
     _scopedOptionalClaims          = scopedOptionalClaims;
     _consentExternalService        = consentExternalService;
     _externalServicesStore         = externalServicesStore;
     _scopedOverrideRawScopeValues  = scopedOverrideRawScopeValues;
     _consentDiscoveryCacheAccessor = consentDiscoveryCacheAccessor;
     _tokenExchangeOptions          = tokenExchangeOptions.Value;
     _tokenValidator                = tokenValidator;
     _logger = logger;
 }
Esempio n. 10
0
 public DefaultAuthorizationCodeStore(
     IPersistedGrantStore store,
     PersistentGrantSerializer serializer,
     ILogger <DefaultAuthorizationCodeStore> logger)
     : base(Constants.PersistedGrantTypes.AuthorizationCode, store, serializer, logger)
 {
 }
 public DefaultUserConsentStore(
     IPersistedGrantStore store,
     PersistentGrantSerializer serializer,
     ILogger <DefaultUserConsentStore> logger)
     : base(Constants.PersistedGrantTypes.UserConsent, store, serializer, logger)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="DefaultPersistedGrantService"/> class.
 /// </summary>
 /// <param name="store">The store.</param>
 /// <param name="serializer">The serializer.</param>
 /// <param name="logger">The logger.</param>
 public DefaultPersistedGrantService(IPersistedGrantStore store,
                                     IPersistentGrantSerializer serializer,
                                     ILogger <DefaultPersistedGrantService> logger)
 {
     _store      = store;
     _serializer = serializer;
     _logger     = logger;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="DefaultRefreshTokenStore"/> class.
 /// </summary>
 /// <param name="store">The store.</param>
 /// <param name="serializer">The serializer.</param>
 /// <param name="handleGenerationService">The handle generation service.</param>
 /// <param name="logger">The logger.</param>
 public DefaultRefreshTokenStore(
     IPersistedGrantStore store,
     IPersistentGrantSerializer serializer,
     IHandleGenerationService handleGenerationService,
     ILogger <DefaultRefreshTokenStore> logger)
     : base(IdentityServerConstants.PersistedGrantTypes.RefreshToken, store, serializer, handleGenerationService, logger)
 {
 }
Esempio n. 14
0
 public DefaultUserConsentStore(
     IPersistedGrantStore store,
     IPersistentGrantSerializer serializer,
     IHandleGenerationService handleGenerationService,
     ILogger <DefaultUserConsentStore> logger)
     : base(Constants.PersistedGrantTypes.UserConsent, store, serializer, handleGenerationService, logger)
 {
 }
Esempio n. 15
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DefaultAuthorizationCodeStore"/> class.
 /// </summary>
 /// <param name="store">The store.</param>
 /// <param name="serializer">The serializer.</param>
 /// <param name="handleGenerationService">The handle generation service.</param>
 /// <param name="logger">The logger.</param>
 public DefaultBackChannelAuthenticationRequestStore(
     IPersistedGrantStore store,
     IPersistentGrantSerializer serializer,
     IHandleGenerationService handleGenerationService,
     ILogger <DefaultBackChannelAuthenticationRequestStore> logger)
     : base(IdentityServerConstants.PersistedGrantTypes.BackChannelAuthenticationRequest, store, serializer, handleGenerationService, logger)
 {
 }
Esempio n. 16
0
 /// <summary>
 /// Creates a new instance of <see cref="DefaultAuthorizationCodeChallengeStore"/>.
 /// </summary>
 /// <param name="store">Interface for persisting any type of grant.</param>
 /// <param name="serializer">Interface for persisted grant serialization.</param>
 /// <param name="handleGenerationService">Interface for the handle generation service.</param>
 /// <param name="logger">Represents a type used to perform logging.</param>
 public DefaultAuthorizationCodeChallengeStore(
     IPersistedGrantStore store,
     IPersistentGrantSerializer serializer,
     IHandleGenerationService handleGenerationService,
     ILogger <DefaultAuthorizationCodeChallengeStore> logger
     ) : base("trusted_device_authorization_code", store, serializer, handleGenerationService, logger)
 {
 }
 public MyAwesomeTests(IPersistedGrantStore persistedGrantStore,
                       IDependency d)
 {
     _d = d;
     _persistedGrantStore = persistedGrantStore;
     _key      = "__the_key";
     _clientId = "__the_client";
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="DefaultAuthorizationCodeStore"/> class.
 /// </summary>
 /// <param name="store">The store.</param>
 /// <param name="serializer">The serializer.</param>
 /// <param name="handleGenerationService">The handle generation service.</param>
 /// <param name="logger">The logger.</param>
 public DefaultAuthorizationCodeStore(
     IPersistedGrantStore store,
     IPersistentGrantSerializer serializer,
     IHandleGenerationService handleGenerationService,
     ILogger <DefaultAuthorizationCodeStore> logger)
     : base(IdentityServerConstants.PersistedGrantTypes.AuthorizationCode, store, serializer, handleGenerationService, logger)
 {
 }
Esempio n. 19
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DefaultAuthorizationCodeStore"/> class.
 /// </summary>
 /// <param name="store">The store.</param>
 /// <param name="serializer">The serializer.</param>
 /// <param name="handleGenerationService">The handle generation service.</param>
 /// <param name="logger">The logger.</param>
 public JWTBasedAuthorizationCodeStore(
     IPersistedGrantStore store,
     IPersistentGrantSerializer serializer,
     IHandleGenerationService handleGenerationService,
     IMemoryCache cache,
     ILogger <JWTBasedAuthorizationCodeStore> logger)
     : base(IdentityServerConstants.PersistedGrantTypes.AuthorizationCode, store, serializer, handleGenerationService, cache, logger)
 {
 }
Esempio n. 20
0
 public MyDefaultReferenceTokenStore(
     IHashFixer hashFixer,
     IPersistedGrantStore store,
     IPersistentGrantSerializer serializer,
     IHandleGenerationService handleGenerationService,
     ILogger <DefaultReferenceTokenStore> logger) :
     base(store, serializer, handleGenerationService, logger)
 {
     _hashFixer = hashFixer;
 }
Esempio n. 21
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MyTokenRevocationResponseGenerator" /> class.
 /// </summary>
 /// <param name="idsTokenRevocationResponseGenerator">The original IdentityServer4 MyTokenRevocationResponseGenerator.</param>
 /// <param name="logger">The logger.</param>
 public MyTokenRevocationResponseGenerator(
     IPersistedGrantStore persistedGrantStore,
     IBackgroundTaskQueue <Delete> taskQueueDelete,
     Duende.IdentityServer.ResponseHandling.TokenRevocationResponseGenerator idsTokenRevocationResponseGenerator,
     ILogger <MyTokenRevocationResponseGenerator> logger)
 {
     _persistedGrantStore = persistedGrantStore;
     _taskQueueDelete     = taskQueueDelete;
     _idsTokenRevocationResponseGenerator = idsTokenRevocationResponseGenerator;
     Logger = logger;
 }
Esempio n. 22
0
 public PersistedGrantStoreExtra(
     IClientStoreExtra clientStoreExtra,
     InMemoryPersistedGrantStore inMemoryPersistedGrantStore,
     IRefreshTokenKeyObfuscator refreshTokenKeyObfuscator,
     ILogger <PersistedGrantStoreExtra> logger)
 {
     _clientStoreExtra            = clientStoreExtra;
     _inMemoryPersistedGrantStore = inMemoryPersistedGrantStore;
     _refreshTokenKeyObfuscator   = refreshTokenKeyObfuscator;
     _logger = logger;
 }
Esempio n. 23
0
 public UnitTest_PersistedGrantStore(
     DatabaseInitializer <UnitTest_PersistedGrantStore> databaseInitializer,
     ICosmonautClient cosmonautClient,
     ICosmosStore <PersistedGrantEntity> persistedGrantCosmosStore,
     IPersistedGrantStore persistedGrantStore)
 {
     _databaseInitializer       = databaseInitializer;
     _cosmonautClient           = cosmonautClient;
     _persistedGrantCosmosStore = persistedGrantCosmosStore;
     _persistedGrantStore       = persistedGrantStore;
 }
Esempio n. 24
0
 /// <summary>
 /// Ctor.
 /// </summary>
 public DefaultSessionManagementService(
     IServerSideTicketService serverSideTicketService,
     IServerSideSessionStore serverSideSessionStore,
     IPersistedGrantStore persistedGrantStore,
     IBackChannelLogoutService backChannelLogoutService)
 {
     _serverSideTicketService  = serverSideTicketService;
     _serverSideSessionStore   = serverSideSessionStore;
     _persistedGrantStore      = persistedGrantStore;
     _backChannelLogoutService = backChannelLogoutService;
 }
Esempio n. 25
0
 public LogoutModel(SignInManager <ApplicationUser> signInManager,
                    IIdentityServerInteractionService interaction,
                    IEventService events,
                    ILogger <LogoutModel> logger,
                    IPersistedGrantStore persistedGrantStore)
 {
     _signInManager       = signInManager;
     _interaction         = interaction;
     _events              = events;
     _logger              = logger;
     _persistedGrantStore = persistedGrantStore;
 }
Esempio n. 26
0
        public PersistedGrantTests(TestContext context)
        {
            this._ = context;
            var client = new AmazonDynamoDBClient(awsAccessKeyId: "fakeMyKeyId", awsSecretAccessKey: "fakeSecretAccessKey", new AmazonDynamoDBConfig {
                ServiceURL = "http://localhost:8000"
            });

            this.persistedGrantStore = new PersistedGrantStore(client, new Extensions.DynamoDBOptions {
                DynamoDBContextConfig = new DynamoDBContextConfig {
                    TableNamePrefix = "local-"
                }
            }, Mock.Of <ILogger <PersistedGrantStore> >());
        }
 /// <summary>   Constructor. </summary>
 /// <param name="interaction">      The interaction. </param>
 /// <param name="clientStore">      The client store. </param>
 /// <param name="resourceStore">    The resource store. </param>
 /// <param name="grantStore">       The grant store. </param>
 /// <param name="stringLocalizer">  The string localizer. </param>
 public ConsentService(
     IIdentityServerInteractionService interaction,
     IClientStore clientStore,
     IResourceStore resourceStore,
     IPersistedGrantStore grantStore,
     IStringLocalizer <ConsentOptions> stringLocalizer)
 {
     _interaction   = interaction;
     _clientStore   = clientStore;
     _resourceStore = resourceStore;
     _grantStore    = grantStore;
     _localizer     = stringLocalizer;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="DefaultRefreshTokenStore"/> class.
 /// </summary>
 /// <param name="store">The store.</param>
 /// <param name="serializer">The serializer.</param>
 /// <param name="handleGenerationService">The handle generation service.</param>
 /// <param name="logger">The logger.</param>
 public MyDefaultRefreshTokenStore(
     IHashFixer hashFixer,
     IPersistedGrantStore store,
     IPersistentGrantSerializer serializer,
     IHandleGenerationService handleGenerationService,
     IBackgroundTaskQueue <Delete> taskQueueDelete,
     IBackgroundTaskQueue <Write> taskQueueWrite,
     ILogger <DefaultRefreshTokenStore> logger)
     : base(IdentityServerConstants.PersistedGrantTypes.RefreshToken, store, serializer, handleGenerationService, logger)
 {
     _hashFixer       = hashFixer;
     _taskQueueDelete = taskQueueDelete;
     _taskQueueWrite  = taskQueueWrite;
 }
Esempio n. 29
0
 /// <summary>
 /// Ctor.
 /// </summary>
 public DefaultSessionCoordinationService(
     IdentityServerOptions options,
     IPersistedGrantStore persistedGrantStore,
     IClientStore clientStore,
     IBackChannelLogoutService backChannelLogoutService,
     ILogger <DefaultSessionCoordinationService> logger,
     IServerSideSessionStore serverSideSessionStore = null)
 {
     Options                  = options;
     PersistedGrantStore      = persistedGrantStore;
     ClientStore              = clientStore;
     BackChannelLogoutService = backChannelLogoutService;
     Logger = logger;
     ServerSideSessionStore = serverSideSessionStore;
 }
Esempio n. 30
0
 /// <inheritdoc />
 public AccountController(ISignInManager signInManager, IAuthService authService, ILogger logger,
                          IEventService events,
                          IPersistedGrantStore persistedGrantStore,
                          IUserSession userSession, IIdentityServerInteractionService interaction,
                          IPersistedGrantService persistedGrantService)
 {
     _signInManager         = signInManager;
     _authService           = authService;
     _logger                = logger;
     _events                = events;
     _persistedGrantStore   = persistedGrantStore;
     _userSession           = userSession;
     _interaction           = interaction;
     _persistedGrantService = persistedGrantService;
 }