Exemplo n.º 1
0
        public async Task Invoke(HttpContext httpContext, IJsonWebKeySetService keyService, IOptions <JwksOptions> options)
        {
            if (!string.IsNullOrEmpty(_jws))
            {
                await httpContext.Response.WriteAsync(_jws);

                return;
            }

            var faker           = new Faker();
            var tokenHandler    = new JwtSecurityTokenHandler();
            var key             = keyService.GetCurrent();
            var tokenDescriptor = new SecurityTokenDescriptor
            {
                Subject = new ClaimsIdentity(new Claim[]
                {
                    new Claim(JwtRegisteredClaimNames.UniqueName, faker.Person.UserName),
                    new Claim(JwtRegisteredClaimNames.Amr, "Fake"),
                    new Claim(JwtRegisteredClaimNames.Email, faker.Person.Email),
                    new Claim(JwtRegisteredClaimNames.GivenName, faker.Person.FullName),
                }),
                Expires            = DateTime.UtcNow.AddHours(1),
                Audience           = "jwt-test",
                Issuer             = Server.ServerUrl,
                SigningCredentials = key
            };
            var jwt = tokenHandler.CreateToken(tokenDescriptor);

            _jws = tokenHandler.WriteToken(jwt);
            await httpContext.Response.WriteAsync(_jws);
        }
Exemplo n.º 2
0
 public GenericStoreServiceTest(TWarmup warmup)
 {
     WarmupData       = warmup;
     _keyService      = WarmupData.Services.GetRequiredService <IJsonWebKeySetService>();
     _jsonWebKeyStore = WarmupData.Services.GetRequiredService <IJsonWebKeyStore>();
     this.WarmupData.Clear();
 }
Exemplo n.º 3
0
        public Decode(IJsonWebKeySetService jwksService, IDataProtectionProvider provider)
        {
            // this service provides us with rotating signing keys
            _jwksService = jwksService;

            // this service provides us with rotating encryption keys
            _protector = provider.CreateProtector($"App_{DateTime.UtcNow:yyyy-MM-dd}");
        }
Exemplo n.º 4
0
 public AuthenticationService(SignInManager <IdentityUser> signInManager, UserManager <IdentityUser> userManager, IOptions <AppSettings> appSettings, IOptions <AppTokenSettings> appTokenSettingsSettings, ApplicationDbContext context, IJsonWebKeySetService jwksService, IAspNetUser aspNetUser)
 {
     SignInManager             = signInManager;
     UserManager               = userManager;
     _appSettings              = appSettings.Value;
     _appTokenSettingsSettings = appTokenSettingsSettings.Value;
     _jwksService              = jwksService;
     _aspNetUser               = aspNetUser;
     _context = context;
 }
Exemplo n.º 5
0
 public UserLoginProvider(UserManager <IdentityUser> userManager,
                          SignInManager <IdentityUser> signInManager,
                          ApplicationDbContext context,
                          IJsonWebKeySetService jwksService)
 {
     _userManager   = userManager;
     _signInManager = signInManager;
     _context       = context;
     _jwksService   = jwksService;
 }
        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();
        }
        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();
        }
Exemplo n.º 8
0
        public async Task Invoke(HttpContext httpContext, IJsonWebKeySetService keyService, IOptions <JwksOptions> options)
        {
            var keys = new
            {
                keys = keyService.GetLastKeysCredentials(options.Value.AlgorithmsToKeep)?.Select(PublicJsonWebKey.FromJwk)
            };

            await httpContext.Response.WriteAsync(JsonSerializer.Serialize(keys, new JsonSerializerOptions()
            {
                IgnoreNullValues = true
            }));
        }
Exemplo n.º 9
0
 public AuthController(SignInManager <IdentityUser> signInManager,
                       UserManager <IdentityUser> userManager,
                       IOptions <Token> appSettings, IMessageBus bus,
                       IAspNetUser aspNetUser,
                       IJsonWebKeySetService jsonWebKeySetService,
                       AuthenticationService authenticationService)
 {
     _signInManager         = signInManager;
     _userManager           = userManager;
     _appSettings           = appSettings.Value;
     _bus                   = bus;
     _aspNetUser            = aspNetUser;
     _jsonWebKeySetService  = jsonWebKeySetService;
     _authenticationService = authenticationService;
 }
Exemplo n.º 10
0
 public Create(IJsonWebKeySetService jwksService, IDataProtectionProvider provider)
 {
     _jwksService = jwksService;
     _protector   = provider.CreateProtector($"App_{DateTime.UtcNow:yyyy-MM-dd}");
 }
 public RestrictedController(IJsonWebKeySetService jwksService)
 {
     _jwksService = jwksService;
 }
 public AuthenticationService(IConfiguration configuration, IJsonWebKeySetService jsonWebKeySetService, IHttpContextAccessor httpContextAccessor)
 {
     _configuration        = configuration;
     _jsonWebKeySetService = jsonWebKeySetService;
     _httpContextAccessor  = httpContextAccessor;
 }
Exemplo n.º 13
0
 public AuthController(SignInManager <IdentityUser> signInManager, UserManager <IdentityUser> userManager, IJsonWebKeySetService jwksService)
 {
     _signInManager = signInManager;
     _userManager   = userManager;
     _jwksService   = jwksService;
 }
Exemplo n.º 14
0
 public JwTokenService(JwTokenConfig jwTokenConfig, IJsonWebKeySetService jsonWebKeySetService)
 {
     _jwTokenConfig        = jwTokenConfig;
     _jsonWebKeySetService = jsonWebKeySetService;
 }
 public KeyServiceInMemoryTest(WarmupInMemoryStore inMemoryWarmup)
 {
     InMemoryWarmupData = inMemoryWarmup;
     _keyService        = InMemoryWarmupData.Services.GetRequiredService <IJsonWebKeySetService>();
     _jsonWebKeyStore   = InMemoryWarmupData.Services.GetRequiredService <IJsonWebKeyStore>();
 }
Exemplo n.º 16
0
 public KeyServiceDatabaseTest(WarmupDatabaseInMemory databaseInMemory)
 {
     DatabaseInMemoryData = databaseInMemory;
     _keyService          = DatabaseInMemoryData.Services.GetRequiredService <IJsonWebKeySetService>();
     _database            = DatabaseInMemoryData.Services.GetRequiredService <AspNetGeneralContext>();
 }
Exemplo n.º 17
0
 /// <summary>Constructor for IdentityServer4KeyStore.</summary>
 /// <param name="keyService"></param>
 /// <param name="memoryCache"></param>
 /// <param name="options"></param>
 public IdentityServer4KeyStore(IJsonWebKeySetService keyService, IMemoryCache memoryCache, IOptions <JwksOptions> options)
 {
     _keyService  = keyService;
     _memoryCache = memoryCache;
     _options     = options;
 }
Exemplo n.º 18
0
 public KeyServiceFileSystemTest(WarmupFileStore fileStoreWarmup)
 {
     FileStoreWarmupData = fileStoreWarmup;
     _keyService         = FileStoreWarmupData.Services.GetRequiredService <IJsonWebKeySetService>();
     _jsonWebKeyStore    = FileStoreWarmupData.Services.GetRequiredService <IJsonWebKeyStore>();
 }