コード例 #1
0
 public JsonWebKeySetServiceTests()
 {
     _options     = new Mock <IOptions <JwksOptions> >();
     _store       = new InMemoryStore(_options.Object);
     _jwksService = new JwksService(_store, new JwkService(), _options.Object);
     _options.Setup(s => s.Value).Returns(new JwksOptions());
 }
コード例 #2
0
 public GenericStoreServiceTest(TWarmup warmup)
 {
     WarmupData = warmup;
     _store     = WarmupData.Services.GetRequiredService <IJsonWebKeyStore>();
     _options   = WarmupData.Services.GetRequiredService <IOptions <JwtOptions> >();
     this.WarmupData.Clear();
 }
コード例 #3
0
 public GenericStoreServiceTest(TWarmup warmup)
 {
     WarmupData       = warmup;
     _keyService      = WarmupData.Services.GetRequiredService <IJsonWebKeySetService>();
     _jsonWebKeyStore = WarmupData.Services.GetRequiredService <IJsonWebKeyStore>();
     this.WarmupData.Clear();
 }
コード例 #4
0
    public WarmupInMemoryStore()
    {
        var serviceCollection = new ServiceCollection();

        serviceCollection.AddJwksManager().PersistKeysInMemory();
        Services = serviceCollection.BuildServiceProvider();

        _store = Services.GetRequiredService <IJsonWebKeyStore>();
    }
コード例 #5
0
        public WarmupFileStore()
        {
            var serviceCollection = new ServiceCollection();

            serviceCollection.AddLogging();
            serviceCollection.AddMemoryCache();
            serviceCollection.AddJwksManager().PersistKeysToFileSystem(new DirectoryInfo(Path.Combine(Directory.GetCurrentDirectory(), "files")));
            Services         = serviceCollection.BuildServiceProvider();
            _jsonWebKeyStore = Services.GetRequiredService <IJsonWebKeyStore>();
        }
コード例 #6
0
        public WarmupDatabaseInMemory()
        {
            var serviceCollection = new ServiceCollection();

            void DatabaseOptions(DbContextOptionsBuilder opt) => opt.UseInMemoryDatabase("Tests").EnableSensitiveDataLogging();

            serviceCollection.AddMemoryCache();
            serviceCollection.AddLogging();
            serviceCollection.AddDbContext <AspNetGeneralContext>(DatabaseOptions);

            serviceCollection.AddJwksManager(o =>
            {
                o.Jws = JwsAlgorithm.ES256;
                o.Jwe = JweAlgorithm.RsaOAEP.WithEncryption(Encryption.Aes128CbcHmacSha256);
            })
            .PersistKeysToDatabaseStore <AspNetGeneralContext>();
            Services         = serviceCollection.BuildServiceProvider();
            _jsonWebKeyStore = Services.GetRequiredService <IJsonWebKeyStore>();
        }
コード例 #7
0
    public WarmupDatabaseInMemory()
    {
        var serviceCollection = new ServiceCollection();

        void DatabaseOptions(DbContextOptionsBuilder opt) => opt.UseInMemoryDatabase("Tests").EnableSensitiveDataLogging();

        serviceCollection.AddMemoryCache();
        serviceCollection.AddLogging();
        serviceCollection.AddDbContext <AspNetGeneralContext>(DatabaseOptions);

        serviceCollection.AddJwksManager(o =>
        {
            o.Jws = Algorithm.Create(AlgorithmType.AES, JwtType.Jws);
            o.Jwe = Algorithm.Create(AlgorithmType.AES, JwtType.Jwe);
        })
        .PersistKeysToDatabaseStore <AspNetGeneralContext>();
        Services         = serviceCollection.BuildServiceProvider();
        _jsonWebKeyStore = Services.GetRequiredService <IJsonWebKeyStore>();
    }
コード例 #8
0
 public KeyServiceInMemoryTest(WarmupInMemoryStore inMemoryWarmup)
 {
     InMemoryWarmupData = inMemoryWarmup;
     _keyService        = InMemoryWarmupData.Services.GetRequiredService <IJsonWebKeySetService>();
     _jsonWebKeyStore   = InMemoryWarmupData.Services.GetRequiredService <IJsonWebKeyStore>();
 }
コード例 #9
0
 public JwksService(IJsonWebKeyStore store, IJsonWebKeyService jwkService, IOptions <JwksOptions> options)
 {
     _store      = store;
     _jwkService = jwkService;
     _options    = options;
 }
コード例 #10
0
 public KeyServiceFileSystemTest(WarmupFileStore fileStoreWarmup)
 {
     FileStoreWarmupData = fileStoreWarmup;
     _keyService         = FileStoreWarmupData.Services.GetRequiredService <IJsonWebKeySetService>();
     _jsonWebKeyStore    = FileStoreWarmupData.Services.GetRequiredService <IJsonWebKeyStore>();
 }
コード例 #11
0
ファイル: JwtService.cs プロジェクト: NetDevPack/Security.Jwt
 public JwtService(IJsonWebKeyStore store, IOptions <JwtOptions> options)
 {
     _store   = store;
     _options = options;
 }
コード例 #12
0
        public async Task Invoke(HttpContext httpContext, IJsonWebKeySetService keyService, IJsonWebKeyStore store, IOptions <JwksOptions> options)
        {
            foreach (var securityKeyWithPrivate in store.Get(options.Value.AlgorithmsToKeep))
            {
                securityKeyWithPrivate.SetParameters();
                store.Update(securityKeyWithPrivate);
            }

            keyService.Generate();
            await httpContext.Response.CompleteAsync();
        }
コード例 #13
0
        public async Task Invoke(HttpContext httpContext, IJsonWebKeySetService keyService, IJsonWebKeyStore store, IOptions <JwksOptions> options)
        {
            foreach (var securityKeyWithPrivate in store.Get(JsonWebKeyType.Jws, options.Value.AlgorithmsToKeep))
            {
                store.Revoke(securityKeyWithPrivate);
            }

            keyService.GenerateSigningCredentials();
            await httpContext.Response.CompleteAsync();
        }