private static IOptions <AuditTrailHubOptions> CreateOptions(Jwk?key = null)
        {
            var registration = new AuditTrailHubRegistration("https://idp.example.com/", SignatureAlgorithm.HS256, key ?? SymmetricJwk.None);

            var options = new AuditTrailHubOptions();

            options.Registry.Add(registration);
            options.Policy = options.Registry.BuildPolicy("636C69656E745F6964");

            return(Options.Create(options));
        }
Example #2
0
        public static IAuditTrailHubBuilder Add(this IAuditTrailHubBuilder builder, AuditTrailHubRegistration registration)
        {
            if (registration == null)
            {
                throw new ArgumentNullException(nameof(registration));
            }

            builder.Services.Configure <AuditTrailHubOptions>(options =>
            {
                options.Registry.Add(registration);
            });

            return(builder);
        }
Example #3
0
        public IAuditTrailHubBuilder RegisterClient(AuditTrailHubRegistration registration)
        {
            if (registration == null)
            {
                throw new ArgumentNullException(nameof(registration));
            }

            Services.Configure <AuditTrailHubOptions>(options =>
            {
                options.Registry.Add(registration);
            });

            return(this);
        }
        public void Ctor_InitializeProperties()
        {
            var key  = SymmetricJwk.GenerateKey(128);
            var reg1 = new AuditTrailHubRegistration("client1", SignatureAlgorithm.HS256, key);

            Assert.Equal("client1", reg1.Issuer);
            Assert.Equal(key, reg1.Jwk);
            Assert.Null(reg1.JwksUri);
            Assert.Equal(SignatureAlgorithm.HS256, reg1.SignatureAlgorithm);

            var reg2 = new AuditTrailHubRegistration("client2", SignatureAlgorithm.ES256, "https://demo.identityserver.io/.well-known/openid-configuration/jwks");

            Assert.Equal("client2", reg2.Issuer);
            Assert.Null(reg2.Jwk);
            Assert.Equal("https://demo.identityserver.io/.well-known/openid-configuration/jwks", reg2.JwksUri);
            Assert.Equal(SignatureAlgorithm.ES256, reg2.SignatureAlgorithm);
        }
        public void BuildPolicy()
        {
            const int ValidateSignature = 0x01;
            const int ValidateAudience  = 0x02;
            var       registry          = new AuditTrailHubRegistry();

            var reg1 = new AuditTrailHubRegistration("client1", SignatureAlgorithm.HS256, SymmetricJwk.GenerateKey(128));

            registry.Add(reg1);
            var policy = registry.BuildPolicy("uruk.example.com");

            Assert.Equal(ValidateSignature | ValidateAudience, policy.Control);
            Assert.Single(policy.RequiredAudiences, "uruk.example.com");

            var reg2 = new AuditTrailHubRegistration("client2", SignatureAlgorithm.RS256, "https://demo.identityserver.io/.well-known/openid-configuration/jwks");

            registry.Add(reg2);
            policy = registry.BuildPolicy("uruk.example.com");
            Assert.Equal(ValidateSignature | ValidateAudience, policy.Control);
            Assert.Single(policy.RequiredAudiences, "uruk.example.com");
        }