Ejemplo n.º 1
0
        static async Task Main()
        {
            var client = new AuditTrailClient("https://example.com", "api", new TokenClientOptions {
            });

            var descriptor = new SecEventDescriptor(SymmetricJwk.FromBase64Url("R9MyWaEoyiMYViVWo8Fk4TUGWiSoaW6U1nOqXri8ZXU"), SignatureAlgorithm.HS256)
            {
                Payload = new JwtPayload
                {
                    { "iss", "https://client.example.com" },
                    { "iat", EpochTime.UtcNow },
                    { "jti", "4d3559ec67504aaba65d40b0363faad8" },
                    { "aud", new[] { "https://scim.example.com/Feeds/98d52461fa5bbc879593b7754", "https://scim.example.com/Feeds/5d7604516b1d08641d7676ee7" } },
                    { "events", new JsonObject
                      {
                          { "urn:ietf:params:scim:event:create", new JsonObject
                                {
                                    { "ref", "https://scim.example.com/Users/44f6142df96bd6ab61e7521d9" },
                                    { "attributes", new object[] { "id", "name", "userName", "password", "emails" } }
                                } }
                      } }
                }
            };

            var result = await client.SendAuditTrailAsync(descriptor);

            Console.WriteLine(result.Status);
        }
Ejemplo n.º 2
0
        public void Write_Success()
        {
            var descriptor = new SecEventDescriptor(Jwk.None, SignatureAlgorithm.None)
            {
                Payload = new JwtPayload
                {
                    { "iss", "https://scim.example.com" },
                    { "iat", 1458496404 },
                    { "jti", "4d3559ec67504aaba65d40b0363faad8" },
                    { "aud", new [] { "https://scim.example.com/Feeds/98d52461fa5bbc879593b7754", "https://scim.example.com/Feeds/5d7604516b1d08641d7676ee7" } },
                    { "events", new JsonObject
                      {
                          { "urn:ietf:params:scim:event:create", new ScimCreateEvent
                            {
                                Ref        = "https://scim.example.com/Users/44f6142df96bd6ab61e7521d9",
                                Attributes = { "id", "name", "userName", "password", "emails" }
                            } }
                      } }
                }
            };

            var writer = new JwtWriter();
            var jwt    = writer.WriteTokenString(descriptor);

            AssertJwt.Equal("eyJhbGciOiJub25lIiwidHlwIjoic2VjZXZlbnQrand0In0.eyJpc3MiOiJodHRwczovL3NjaW0uZXhhbXBsZS5jb20iLCJpYXQiOjE0NTg0OTY0MDQsImp0aSI6IjRkMzU1OWVjNjc1MDRhYWJhNjVkNDBiMDM2M2ZhYWQ4IiwiYXVkIjpbImh0dHBzOi8vc2NpbS5leGFtcGxlLmNvbS9GZWVkcy85OGQ1MjQ2MWZhNWJiYzg3OTU5M2I3NzU0IiwiaHR0cHM6Ly9zY2ltLmV4YW1wbGUuY29tL0ZlZWRzLzVkNzYwNDUxNmIxZDA4NjQxZDc2NzZlZTciXSwiZXZlbnRzIjp7InVybjppZXRmOnBhcmFtczpzY2ltOmV2ZW50OmNyZWF0ZSI6eyJyZWYiOiJodHRwczovL3NjaW0uZXhhbXBsZS5jb20vVXNlcnMvNDRmNjE0MmRmOTZiZDZhYjYxZTc1MjFkOSIsImF0dHJpYnV0ZXMiOlsiaWQiLCJuYW1lIiwidXNlck5hbWUiLCJwYXNzd29yZCIsImVtYWlscyJdfX19.", jwt);
        }
Ejemplo n.º 3
0
        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            while (!stoppingToken.IsCancellationRequested)
            {
                var descriptor = new SecEventDescriptor(SymmetricJwk.FromBase64Url("R9MyWaEoyiMYViVWo8Fk4TUGWiSoaW6U1nOqXri8ZXU"), SignatureAlgorithm.HS256)
                {
                    Payload = new JwtPayload
                    {
                        { "iss", "https://client.example.com" },
                        { "iat", EpochTime.UtcNow },
                        { "jti", Guid.NewGuid().ToString("N") },
                        { "aud", new[] { "https://scim.example.com/Feeds/98d52461fa5bbc879593b7754", "https://scim.example.com/Feeds/5d7604516b1d08641d7676ee7" } },
                        { "events", new JsonObject
                          {
                              { "urn:ietf:params:scim:event:create", new JsonObject
                                {
                                    { "ref", "https://scim.example.com/Users/44f6142df96bd6ab61e7521d9" },
                                    { "attributes", new object[] { "id", "name", "userName", "password", "emails" } }
                                } }
                          } }
                    }
                };

                await _client.SendAuditTrailAsync(descriptor);
            }
        }
        private static string CreateSecurityEventToken()
        {
            var key = GetJwk();

            var token = new SecEventDescriptor(key, SignatureAlgorithm.HS256)
            {
                Payload = new JwtPayload
                {
                    { "iss", "Bob" },
                    { "aud", "uruk" },
                    { "iat", EpochTime.UtcNow },
                    { "jti", Guid.NewGuid().ToString("N") },
                    { "events", new JsonObject {
                          { "test", new object() }
                      } }
                }
            };

            return(new JwtWriter().WriteTokenString(token));
        }
Ejemplo n.º 5
0
        static void Main()
        {
            // Creates a symmetric key defined for the 'HS256' algorithm
            var signingKey = SymmetricJwk.FromBase64Url("R9MyWaEoyiMYViVWo8Fk4TUGWiSoaW6U1nOqXri8_XU");

            // Creates a SecEvent descriptor with all its properties
            var descriptor = new SecEventDescriptor(signingKey, SignatureAlgorithm.HS256)
            {
                Payload = new JwtPayload
                {
                    { JwtClaimNames.Iss, "https://idp.example.com/" },
                    { JwtClaimNames.Jti, "756E69717565206964656E746966696572" },
                    { JwtClaimNames.Iat, 1508184845 },
                    { JwtClaimNames.Aud, "636C69656E745F6964" },
                    { SecEventClaimNames.Toe, EpochTime.UtcNow },
                    { SecEventClaimNames.Txn, "6964656E74" },
                    { SecEventClaimNames.Events, new JsonObject
                      {
                          new AccountDisabledSecEvent
                          {
                              { SecEvent.SubjectAttribute, new EmailSubjectIdentifier("*****@*****.**") },
                              { AccountDisabledSecEvent.ReasonAttribute, "hijacking" },
                              { "custom_attribute", "hello world" }
                          }
                      } }
                }
            };

            // Generates the UTF-8 string representation of the JWT
            var writer = new JwtWriter();
            var token  = writer.WriteTokenString(descriptor);

            Console.WriteLine("The JWT is:");
            Console.WriteLine(descriptor);
            Console.WriteLine();
            Console.WriteLine("Its compact form is:");
            Console.WriteLine(token);
        }
Ejemplo n.º 6
0
        private static SecEventDescriptor CreateDescriptor()
        {
            var descriptor = new SecEventDescriptor(SymmetricJwk.FromByteArray(new byte[16]), SignatureAlgorithm.HS256)
            {
                Payload = new JwtPayload
                {
                    { "iss", "https://client.example.com" },
                    { "iat", EpochTime.UtcNow },
                    { "jti", "4d3559ec67504aaba65d40b0363faad8" },
                    { "aud", new[] { "https://scim.example.com/Feeds/98d52461fa5bbc879593b7754", "https://scim.example.com/Feeds/5d7604516b1d08641d7676ee7" } },
                    { "events", new JsonObject
                      {
                          { "urn:ietf:params:scim:event:create", new JsonObject
                            {
                                { "ref", "https://scim.example.com/Users/44f6142df96bd6ab61e7521d9" },
                                { "attributes", new object[] { "id", "name", "userName", "password", "emails" } }
                            } }
                      } }
                }
            };

            return(descriptor);
        }