Example #1
0
        public async Task ListAllEventHooks()
        {
            var testClient        = TestClient.Create();
            var testEventHookName = $"{SdkPrefix}:{nameof(ListAllEventHooks)} Test Event Hook Name ({TestClient.RandomString(6)})";

            var existingEventHookIds = new HashSet <string>();

            await foreach (IEventHook existingEventHook in testClient.EventHooks.ListEventHooks())
            {
                existingEventHookIds.Add(existingEventHook.Id);
            }

            var testEventHookIds = new HashSet <string>();

            for (int i = 0; i < 5; i++)
            {
                var createdEventHook = await testClient.EventHooks.CreateEventHookAsync(
                    new EventHook
                {
                    Name   = $"{testEventHookName} {i}",
                    Events = new EventSubscriptions
                    {
                        Type  = EventType,
                        Items = new string[]
                        {
                            "user.lifecycle.create",
                            "user.lifecycle.activate",
                        },
                    },
                    Channel = new EventHookChannel
                    {
                        Type    = "HTTP",
                        Version = "1.0.0",
                        Config  = new EventHookChannelConfig
                        {
                            Uri     = "https://www.example.com/eventHooks",
                            Headers = new List <IEventHookChannelConfigHeader>
                            {
                                new EventHookChannelConfigHeader
                                {
                                    Key   = "X-Test-Header",
                                    Value = "Test header value",
                                },
                            },
                            AuthScheme = new EventHookChannelConfigAuthScheme
                            {
                                Type  = "HEADER",
                                Key   = "Authorization",
                                Value = "Test-Api-Key",
                            },
                        },
                    },
                });

                testEventHookIds.Add(createdEventHook.Id);
            }

            try
            {
                var allEventHookIds    = new HashSet <string>();
                var allEventHooks      = testClient.EventHooks.ListEventHooks();
                var allEventHooksCount = await allEventHooks.CountAsync();

                allEventHooksCount.Should().BeGreaterThan(0);
                allEventHooksCount.Should().Be(existingEventHookIds.Count + testEventHookIds.Count);

                await foreach (IEventHook eventHook in allEventHooks)
                {
                    allEventHookIds.Add(eventHook.Id);
                }

                foreach (string testEventHookId in testEventHookIds)
                {
                    Assert.Contains(testEventHookId, allEventHookIds);
                }
            }
            finally
            {
                foreach (string testEventHookId in testEventHookIds)
                {
                    await testClient.EventHooks.DeactivateEventHookAsync(testEventHookId);

                    await testClient.EventHooks.DeleteEventHookAsync(testEventHookId);
                }
            }
        }
Example #2
0
        public async Task RetrieveEventHook()
        {
            var testClient        = TestClient.Create();
            var testEventHookName = $"{SdkPrefix}:{nameof(RetrieveEventHook)} Test Event Hook Name ({TestClient.RandomString(6)})";

            var createdEventHook = await testClient.EventHooks.CreateEventHookAsync(
                new EventHook
            {
                Name   = testEventHookName,
                Events = new EventSubscriptions
                {
                    Type  = EventType,
                    Items = new string[]
                    {
                        "user.lifecycle.create",
                        "user.lifecycle.activate",
                    },
                },
                Channel = new EventHookChannel
                {
                    Type    = "HTTP",
                    Version = "1.0.0",
                    Config  = new EventHookChannelConfig
                    {
                        Uri     = "https://www.example.com/eventHooks",
                        Headers = new List <IEventHookChannelConfigHeader>
                        {
                            new EventHookChannelConfigHeader
                            {
                                Key   = "X-Test-Header",
                                Value = "Test header value",
                            },
                        },
                        AuthScheme = new EventHookChannelConfigAuthScheme
                        {
                            Type  = "HEADER",
                            Key   = "Authorization",
                            Value = "Test-Api-Key",
                        },
                    },
                },
            });

            try
            {
                createdEventHook.Id.Should().NotBeNullOrEmpty();

                var retrievedEventHook = await testClient.EventHooks.GetEventHookAsync(createdEventHook.Id);

                retrievedEventHook.Id.Should().NotBeNullOrEmpty();
                retrievedEventHook.Name.Should().Be(testEventHookName);
                retrievedEventHook.Events.Should().NotBeNull();
                retrievedEventHook.Events.Items.Should().NotBeNull();
                retrievedEventHook.Events.Items.Count.Should().Be(2);
                retrievedEventHook.Channel.Should().NotBeNull();
                retrievedEventHook.Channel.Config.Should().NotBeNull();
                retrievedEventHook.Channel.Config.Uri.Should().Be("https://www.example.com/eventHooks");
            }
            finally
            {
                await testClient.EventHooks.DeactivateEventHookAsync(createdEventHook.Id);

                await testClient.EventHooks.DeleteEventHookAsync(createdEventHook.Id);
            }
        }
        public async Task GetLinkedObjectForUser()
        {
            var client       = TestClient.Create();
            var randomString = TestClient.RandomString(6); // use of guid results in field values that are too long

            var primaryRelationshipName    = $"dotnet_sdk_{nameof(GetLinkedObjectForUser)}_primary_{randomString}";
            var associatedRelationshipName = $"dotnet_sdk_{nameof(GetLinkedObjectForUser)}_associated_{randomString}";

            var createdPrimaryUser = await client.Users.CreateUserAsync(
                new CreateUserWithPasswordOptions
            {
                Profile = new UserProfile
                {
                    FirstName = "John-Primary",
                    LastName  = $"{nameof(GetLinkedObjectForUser)}",
                    Email     = $"{nameof(GetLinkedObjectForUser)}-primary-dotnet-sdk-{randomString}@example.com",
                    Login     = $"{nameof(GetLinkedObjectForUser)}-primary-dotnet-sdk-{randomString}@example.com",
                },
                RecoveryQuestion = "Answer to life, the universe, & everything",
                RecoveryAnswer   = "42 of course",
                Password         = "******",
                Activate         = true,
            });

            var createdAssociatedUser = await client.Users.CreateUserAsync(
                new CreateUserWithPasswordOptions
            {
                Profile = new UserProfile
                {
                    FirstName = "David-Associated",
                    LastName  = $"{nameof(GetLinkedObjectForUser)}",
                    Email     = $"{nameof(GetLinkedObjectForUser)}-associated-dotnet-sdk-{randomString}@example.com",
                    Login     = $"{nameof(GetLinkedObjectForUser)}-associated-dotnet-sdk-{randomString}@example.com",
                },
                RecoveryQuestion = "Answer to life, the universe, & everything",
                RecoveryAnswer   = "42 of course",
                Password         = "******",
                Activate         = true,
            });

            var createdLinkedObjectDefinition = await client.LinkedObjects.AddLinkedObjectDefinitionAsync(
                new LinkedObject
            {
                Primary = new LinkedObjectDetails
                {
                    Name        = primaryRelationshipName,
                    Title       = "Primary",
                    Description = "Primary link property",
                    Type        = "USER",
                },
                Associated = new LinkedObjectDetails
                {
                    Name        = associatedRelationshipName,
                    Title       = "Associated",
                    Description = "Associated link property",
                    Type        = "USER",
                },
            });

            Thread.Sleep(3000); // allow for user replication prior to read attempt

            try
            {
                await createdAssociatedUser.SetLinkedObjectAsync(primaryRelationshipName, createdPrimaryUser.Id);

                var links = await createdAssociatedUser.GetLinkedObjects(primaryRelationshipName).ToListAsync();

                links.Should().NotBeNull();
                links.Count.Should().Be(1);
            }
            finally
            {
                await createdPrimaryUser.DeactivateAsync();

                await createdPrimaryUser.DeactivateOrDeleteAsync();

                await createdAssociatedUser.DeactivateAsync();

                await createdAssociatedUser.DeactivateOrDeleteAsync();

                await client.LinkedObjects.DeleteLinkedObjectDefinitionAsync(primaryRelationshipName);
            }
        }
Example #4
0
        public async Task DeleteEventHook()
        {
            var testClient        = TestClient.Create();
            var testEventHookName = $"{SdkPrefix}:{nameof(DeleteEventHook)} Test Event Hook Name ({TestClient.RandomString(6)})";

            var createdEventHook = await testClient.EventHooks.CreateEventHookAsync(
                new EventHook
            {
                Name   = testEventHookName,
                Events = new EventSubscriptions
                {
                    Type  = EventType,
                    Items = new string[]
                    {
                        "user.lifecycle.create",
                        "user.lifecycle.activate",
                    },
                },
                Channel = new EventHookChannel
                {
                    Type    = "HTTP",
                    Version = "1.0.0",
                    Config  = new EventHookChannelConfig
                    {
                        Uri     = "https://www.example.com/eventHooks",
                        Headers = new List <IEventHookChannelConfigHeader>
                        {
                            new EventHookChannelConfigHeader
                            {
                                Key   = "X-Test-Header",
                                Value = "Test header value",
                            },
                        },
                        AuthScheme = new EventHookChannelConfigAuthScheme
                        {
                            Type  = "HEADER",
                            Key   = "Authorization",
                            Value = "Test-Api-Key",
                        },
                    },
                },
            });

            createdEventHook.Id.Should().NotBeNullOrEmpty();

            var retrievedEventHook = await testClient.EventHooks.GetEventHookAsync(createdEventHook.Id);

            retrievedEventHook.Id.Should().Be(createdEventHook.Id);

            await testClient.EventHooks.DeactivateEventHookAsync(createdEventHook.Id);

            await testClient.EventHooks.DeleteEventHookAsync(createdEventHook.Id);

            var ex = await Assert.ThrowsAsync <OktaApiException>(() =>
                                                                 testClient.EventHooks.GetEventHookAsync(createdEventHook.Id));

            ex.StatusCode.Should().Be(404);
        }
        public async Task GetAllLinkedObjectDefinitions()
        {
            var testClient         = TestClient.Create();
            var randomString       = TestClient.RandomString(6);
            var testPrimaryName    = $"{SdkPrefix}_{nameof(GetAllLinkedObjectDefinitions)}_primary_{randomString}";
            var testAssociatedName = $"{SdkPrefix}_{nameof(GetAllLinkedObjectDefinitions)}_associated_{randomString}";

            var createdLinkedObjectDefinition1 = await testClient.LinkedObjects.AddLinkedObjectDefinitionAsync(
                new LinkedObject
            {
                Primary = new LinkedObjectDetails
                {
                    Name        = $"{testPrimaryName}_1",
                    Title       = "Primary",
                    Description = "Primary link property",
                    Type        = "USER",
                },
                Associated = new LinkedObjectDetails
                {
                    Name        = $"{testAssociatedName}_1",
                    Title       = "Associated",
                    Description = "Associated link property",
                    Type        = "USER",
                },
            });

            var createdLinkedObjectDefinition2 = await testClient.LinkedObjects.AddLinkedObjectDefinitionAsync(
                new LinkedObject
            {
                Primary = new LinkedObjectDetails
                {
                    Name        = $"{testPrimaryName}_2",
                    Title       = "Primary",
                    Description = "Primary link property",
                    Type        = "USER",
                },
                Associated = new LinkedObjectDetails
                {
                    Name        = $"{testAssociatedName}_2",
                    Title       = "Associated",
                    Description = "Associated link property",
                    Type        = "USER",
                },
            });

            try
            {
                var allLinkedObjectDefinitions  = testClient.LinkedObjects.ListLinkedObjectDefinitions();
                var allLinkedObjectPrimaryNames =
                    await allLinkedObjectDefinitions.Select(lod => lod.Primary.Name).ToHashSetAsync();

                var allLinkedObjectAssociatedNames =
                    await allLinkedObjectDefinitions.Select(lod => lod.Associated.Name).ToHashSetAsync();

                Assert.Contains(createdLinkedObjectDefinition1.Primary.Name, allLinkedObjectPrimaryNames);
                Assert.Contains(createdLinkedObjectDefinition2.Primary.Name, allLinkedObjectPrimaryNames);
                Assert.Contains(createdLinkedObjectDefinition1.Associated.Name, allLinkedObjectAssociatedNames);
                Assert.Contains(createdLinkedObjectDefinition2.Associated.Name, allLinkedObjectAssociatedNames);
            }
            finally
            {
                await testClient.LinkedObjects.DeleteLinkedObjectDefinitionAsync(
                    createdLinkedObjectDefinition1.Primary.Name);

                await testClient.LinkedObjects.DeleteLinkedObjectDefinitionAsync(
                    createdLinkedObjectDefinition2.Primary.Name);
            }
        }
        public async Task RemoveGroupTargetFromRole()
        {
            var client = TestClient.Create();
            var guid   = Guid.NewGuid();

            var createdUser = await client.Users.CreateUserAsync(new CreateUserWithPasswordOptions
            {
                Profile = new UserProfile
                {
                    FirstName = "John",
                    LastName  = $"{nameof(RemoveGroupTargetFromRole)}",
                    Email     = $"john-{nameof(RemoveGroupTargetFromRole)}-dotnet-sdk-{guid}@example.com",
                    Login     = $"john-{nameof(RemoveGroupTargetFromRole)}-dotnet-sdk-{guid}@example.com",
                },
                Password = "******",
                Activate = true,
            });

            var createdGroup1 = await client.Groups.CreateGroupAsync(new CreateGroupOptions
            {
                Name        = $"dotnet-sdk:{nameof(RemoveGroupTargetFromRole)}1-{guid}",
                Description = $"dotnet-sdk:{nameof(RemoveGroupTargetFromRole)}1-{guid}",
            });

            var createdGroup2 = await client.Groups.CreateGroupAsync(new CreateGroupOptions
            {
                Name        = $"dotnet-sdk:{nameof(RemoveGroupTargetFromRole)}2-{guid}",
                Description = $"dotnet-sdk:{nameof(RemoveGroupTargetFromRole)}2-{guid}",
            });

            try
            {
                var role = await createdUser.AssignRoleAsync(
                    new AssignRoleRequest
                {
                    Type = RoleType.UserAdmin,
                });

                // Need 2 groups, because if you remove the last one it throws an (expected) exception.
                await createdUser.AddGroupTargetAsync(role.Id, createdGroup1.Id);

                await createdUser.AddGroupTargetAsync(role.Id, createdGroup2.Id);

                var retrievedGroupsForRole = await createdUser.ListGroupTargets(role.Id).ToListAsync();

                retrievedGroupsForRole.Should().Contain(x => x.Id == createdGroup1.Id);
                retrievedGroupsForRole.Should().Contain(x => x.Id == createdGroup2.Id);

                await createdUser.RemoveGroupTargetAsync(role.Id, createdGroup1.Id);

                retrievedGroupsForRole = await createdUser.ListGroupTargets(role.Id).ToListAsync();

                retrievedGroupsForRole.Should().NotContain(x => x.Id == createdGroup1.Id);
            }
            finally
            {
                // Remove the user
                await createdUser.DeactivateAsync();

                await createdUser.DeactivateOrDeleteAsync();

                await createdGroup1.DeleteAsync();

                await createdGroup2.DeleteAsync();
            }
        }
        public async Task DeleteGroupRule()
        {
            var testClient   = TestClient.Create();
            var guid         = Guid.NewGuid();
            var testNickName = $"dotnet-sdk-{nameof(DeleteGroupRule)}";
            var testUserName = $"{testNickName}-{guid}@example.com";

            var profile = new UserProfile
            {
                FirstName    = "John",
                LastName     = $"{nameof(DeleteGroupRule)}",
                Email        = testUserName,
                Login        = testUserName,
                ["nickName"] = testNickName,
            };

            var createdUser = await testClient.Users.CreateUserAsync(new CreateUserWithPasswordOptions
            {
                Profile  = profile,
                Password = "******",
            });

            var createdGroup = await testClient.Groups.CreateGroupAsync(new CreateGroupOptions
            {
                Name        = $"dotnet-sdk:{nameof(DeleteGroupRule)}-{guid}",
                Description = $"dotnet-sdk:{nameof(DeleteGroupRule)}-{guid}",
            });

            Thread.Sleep(3000); // allow user replication prior to read attempt

            var groupRule = new GroupRule
            {
                Type       = "group_rule",
                Name       = $"US group rule ({TestClient.RandomString(6)})", // guid would cause field to be too long
                Conditions = new GroupRuleConditions
                {
                    People = new GroupRulePeopleCondition
                    {
                        Users = new GroupRuleUserCondition
                        {
                            Exclude = new List <string> {
                                createdUser.Id
                            },
                        },
                        Groups = new GroupRuleGroupCondition
                        {
                            Exclude = new List <string>(),
                        },
                    },
                    Expression = new GroupRuleExpression
                    {
                        Value = "user.countryCode==\"US\"",
                        Type  = "urn:okta:expression:1.0",
                    },
                },
                Actions = new GroupRuleAction
                {
                    AssignUserToGroups = new GroupRuleGroupAssignment
                    {
                        GroupIds = new List <string> {
                            createdGroup.Id
                        },
                    },
                },
            };

            var createdGroupRule = await testClient.Groups.CreateGroupRuleAsync(groupRule);

            try
            {
                var retrievedGroupRule = await testClient.Groups.GetGroupRuleAsync(createdGroupRule.Id);

                retrievedGroupRule.Should().NotBeNull();

                await testClient.Groups.DeleteGroupRuleAsync(createdGroupRule.Id);

                Thread.Sleep(3000);
                var ex = await Assert.ThrowsAsync <OktaApiException>(() => testClient.Groups.GetGroupRuleAsync(createdGroup.Id));

                ex.StatusCode.Should().Be(404);
            }
            finally
            {
                await createdUser.DeactivateAsync();

                await createdUser.DeactivateOrDeleteAsync();

                await createdGroup.DeleteAsync();
            }
        }
        [Trait("Category", "NoBacon")] // Tests that don't run on internal CI pipeline
        public async Task ListUsers()
        {
            var client  = TestClient.Create();
            var guid    = Guid.NewGuid();
            var payload = $@"{{
                                ""client_name"": ""dotnet-sdk: Service Client {guid}"",
                                ""response_types"": [
                                  ""token""
                                ],
                                ""grant_types"": [
                                  ""client_credentials""
                                ],
                                ""token_endpoint_auth_method"": ""private_key_jwt"",
                                ""application_type"": ""service"",
                                ""jwks"": {{
                                    ""keys"": [
                                        {{
                                            ""kty"":""RSA"",
                                            ""e"":""AQAB"",
                                            ""n"":""mTjMc8AxU102LT1Jf-1qkGmaSiK4L7DDlC1SMvtyCRbDaiJDIagedfp1w8Pgud8YWOaS5FFx0S6JqGGP2U8OtpowzBcv5sYa-e5LHfnoueTJPj_jnI3fj5omZM1w-ofhFLPZoYEQ7DFYw0yLrzf8zaKB5-9BZ8yyOLhSKqxaOl2s7lw2TrwBRuQpPXmEir70oDPvazd8-An5ow6F5q7mzMtHAt61DJqrosRHiRwh4N37zIX_RNu-Tn1aMktCBl01rdoDyVq7Y4iwNH8ZAtT5thKK2eo8d-jb9TF9PH6LGffYCth157w-K4AZwXw74Ybo5NOux3XpIpKRbFTwvBLp1Q""
                                        }}   
                                   ]
                                }}
                             }}";

            // Register new service
            var service = await client.PostAsync <Resource>(new HttpRequest()
            {
                Uri     = $"/oauth2/v1/clients",
                Payload = JObject.Parse(payload),
            });

            // Create a user so I can assert user list is not empty afterward
            var profile = new UserProfile
            {
                FirstName = "John",
                LastName  = "OAuth-List-Users",
                Email     = $"john-list-users-dotnet-sdk-{guid}@example.com",
                Login     = $"john-list-users-dotnet-sdk-{guid}@example.com",
            };

            profile["nickName"] = "johny-list-users";

            var createdUser = await client.Users.CreateUserAsync(new CreateUserWithPasswordOptions
            {
                Profile  = profile,
                Password = "******",
            });

            try
            {
                // Remove '/' at the end since endpoint fails otherwise
                var oktaDomain = client.Configuration.OktaDomain.Remove(client.Configuration.OktaDomain.Length - 1);

                var grantPayload = $@"{{
                                        ""scopeId"" : ""okta.users.read"",
                                        ""issuer"" : ""{oktaDomain}""
                                    }}";
                // Add grant to the service
                var grantResponse = await client.PostAsync <Resource>(new HttpRequest()
                {
                    Uri     = $"/api/v1/apps/{service.GetProperty<string>("client_id")}/grants",
                    Payload = JObject.Parse(grantPayload),
                });

                // Use OAuth to get list of users
                var jsonPrivateKey = @"{
                                    ""p"":""2-8pgwYv9jrkM2KsbnQmnJZnr69Rsj95M20I1zx5HhM3tgjGSa7d_dELPRkp9Usy8UGISt7eUHpYOVl529irHwbXevuId1Q804aQ_AtNJwpbRY48rw2T8LdtyVSaEyoFMCa8PJwtzZYzKJCKAe5eoXvW5zxB65RaIct0igYcoIs"",
                                    ""kty"":""RSA"",
                                    ""q"":""slkNUY_SCIn95ip7HoPs_IIiNoKOGeesIV1gacyoAycly1vBPMhtar9gwx51nN1tCMVGlSOk583eRJe2omAbqkIEYm1jSWtMdJKQSOJvx812xbF1afMgJDlJ6iRIlcnWEYhNNMCK5s_UR5zE0Mc5jktxDFeiEatriyu6o9hQix8"",
                                    ""d"":""LIpJTKCi9hPTiuUU954hayd3lXNwTVS6Fdny2iUj6iZ22eRp1V_UswECuMy5B-8lWbp1Gu_eASvhElSCB26m3UgHRVy8LP6Lmvm9VlJuZ5NtOK5D0R-gzFLINGdQH1PehzEc44jsTWyu297lgCLrVy-VScHQJodni3txTzxY4jwjILMfLB7OWdKVkvDQ4g70BYTVN5kZKjA9B0lLsofi1gUY_EVlojuvSKbm3HY0JR_JThtEd_nZw_tXTYmlP58plVYX-9JnA8NcFRB6dUNO7XqcXU1SafWqoM9yam1nGSMYRknwjSSTKRdBXHSy7PVxVHhpC72wb3aWNsOqWNo0ZQ"",
                                    ""e"":""AQAB"",
                                    ""qi"":""u1mS53N4BUSoMeOHFd0o4_n3QGH4izNUsiJVBIkv_UZUAk4LYudPEikTWRLqWsrcXmOyZYao5sSaZyt-B2XCkfdnkIhl-Q7b0_W0yt3Eh5XjAzH9oy5Dklog255lh-Y0yoWXvLjq-KEDs7Nd2uIT4gvKU4ymTqybvzazr2jY9qQ"",""dp"":""nCtPBsK1-9oFgJdoaWYApOAH8DBFipSXs3SQ-oTuW_S5coD4jAmniDuQB2p-6LblDXrDFKb8pZi6XL60UO-hUv7As4s4c8NVDb5X5SEBP9-Sv-koHgU-L4eQZY21ejY0SOS4dTFRNNKasQsxc_2XJIOTLc8T3_wPpD-cGQYN_dE"",""dq"":""ZWb4iZ0qICzFLW6N3gXIYrFi3ndQcC4m0jmTLdRs2o4RkRQ0RGj4vS7ex1G0MWI8MjZoMTe49Qs6Cunvr1bRo_YxI_1p7D6Tk9wZKTeFsqaBl1mUlo7jgXUJL5U9p9zAV-uVah7nWuBjo-vgg4wij2MZfZj9zuoWFWThk3LUKKU"",""n"":""mTjMc8AxU102LT1Jf-1qkGmaSiK4L7DDlC1SMvtyCRbDaiJDIagedfp1w8Pgud8YWOaS5FFx0S6JqGGP2U8OtpowzBcv5sYa-e5LHfnoueTJPj_jnI3fj5omZM1w-ofhFLPZoYEQ7DFYw0yLrzf8zaKB5-9BZ8yyOLhSKqxaOl2s7lw2TrwBRuQpPXmEir70oDPvazd8-An5ow6F5q7mzMtHAt61DJqrosRHiRwh4N37zIX_RNu-Tn1aMktCBl01rdoDyVq7Y4iwNH8ZAtT5thKK2eo8d-jb9TF9PH6LGffYCth157w-K4AZwXw74Ybo5NOux3XpIpKRbFTwvBLp1Q""
                                 }";

                var configuration = new OktaClientConfiguration();
                configuration.Scopes = new List <string> {
                    "okta.users.read"
                };
                configuration.ClientId          = service.GetProperty <string>("client_id");
                configuration.PrivateKey        = new JsonWebKeyConfiguration(jsonPrivateKey);
                configuration.AuthorizationMode = AuthorizationMode.PrivateKey;

                var oAuthClient = TestClient.Create(configuration);

                var users = await oAuthClient.Users.ListUsers().ToArrayAsync();

                users.Should().NotBeEmpty();
            }
            finally
            {
                // Delete user
                await createdUser.DeactivateAsync();

                await createdUser.DeactivateOrDeleteAsync();

                // Delete service
                await client.DeleteAsync(new HttpRequest()
                {
                    Uri = $"/oauth2/v1/clients/{service.GetProperty<string>("client_id")}",
                });
            }
        }
Example #9
0
        public async Task RetrieveUserTypeById()
        {
            var testClient = TestClient.Create();

            var testDescription = $"{SdkPrefix}:{nameof(RetrieveUserTypeById)} Test Description";
            var testDisplayName = $"{SdkPrefix}:{nameof(RetrieveUserTypeById)} Test DisplayName";
            var testName        = $"{SdkPrefix}{nameof(RetrieveUserTypeById)}_TestUserType_{TestClient.RandomString(6)}";

            var createdUserType = await testClient.UserTypes.CreateUserTypeAsync(new UserType
            {
                Description = testDescription,
                DisplayName = testDisplayName,
                Name        = testName,
            });

            try
            {
                createdUserType.Id.Should().NotBeNullOrEmpty();

                var retrievedUserType = await testClient.UserTypes.GetUserTypeAsync(createdUserType.Id);

                retrievedUserType.Should().NotBeNull();
                retrievedUserType.Id.Should().Be(createdUserType.Id);
                retrievedUserType.Description.Should().Be(testDescription);
                retrievedUserType.DisplayName.Should().Be(testDisplayName);
            }
            finally
            {
                await testClient.UserTypes.DeleteUserTypeAsync(createdUserType.Id);
            }
        }
Example #10
0
        public async Task UpdateUserType()
        {
            var testClient = TestClient.Create();

            var testDescription = $"{SdkPrefix}:{nameof(UpdateUserType)} Test Description";
            var testDisplayName = $"{SdkPrefix}:{nameof(UpdateUserType)} Test DisplayName";
            var testName        = $"{SdkPrefix}_{nameof(UpdateUserType)}_TestUserType_{TestClient.RandomString(6)}";

            var createdUserType = await testClient.UserTypes.CreateUserTypeAsync(new UserType
            {
                Description = testDescription,
                DisplayName = testDisplayName,
                Name        = testName,
            });

            try
            {
                createdUserType.Id.Should().NotBeNullOrEmpty();

                var updatedDescription = $"{createdUserType.Description} Updated";
                var updatedDisplayName = $"{createdUserType.Description} Updated";

                var updatesToUserType = new UserType
                {
                    Description = updatedDescription,
                    DisplayName = updatedDisplayName,
                };

                var updatedUserType = await testClient.UserTypes.UpdateUserTypeAsync(updatesToUserType, createdUserType.Id);

                updatedUserType.Id.Should().Be(createdUserType.Id);
                updatedUserType.Description.Should().Be(updatedDescription);
                updatedUserType.DisplayName.Should().Be(updatedDisplayName);

                var retrievedUserTypeForValidation = await testClient.UserTypes.GetUserTypeAsync(createdUserType.Id);

                retrievedUserTypeForValidation.Id.Should().Be(createdUserType.Id);
                retrievedUserTypeForValidation.Description.Should().Be(updatedDescription);
                retrievedUserTypeForValidation.DisplayName.Should().Be(updatedDisplayName);
            }
            finally
            {
                await testClient.UserTypes.DeleteUserTypeAsync(createdUserType.Id);
            }
        }
Example #11
0
        public async Task DeleteUserTypeById()
        {
            var testClient      = TestClient.Create();
            var testDescription = $"{SdkPrefix}:{nameof(DeleteUserTypeById)} Test Description";
            var testDisplayName = $"{SdkPrefix}:{nameof(DeleteUserTypeById)} Test DisplayName";
            var testName        = $"{SdkPrefix}_{nameof(DeleteUserTypeById)}_TestUserType_{TestClient.RandomString(6)}";

            var createdUserType = await testClient.UserTypes.CreateUserTypeAsync(new UserType
            {
                Description = testDescription,
                DisplayName = testDisplayName,
                Name        = testName,
            });

            createdUserType.Id.Should().NotBeNullOrEmpty();

            var retrievedUserType = await testClient.UserTypes.GetUserTypeAsync(createdUserType.Id);

            retrievedUserType.Id.Should().Be(createdUserType.Id);

            await testClient.UserTypes.DeleteUserTypeAsync(createdUserType.Id);

            var ex = await Assert.ThrowsAsync <OktaApiException>(() =>
                                                                 testClient.UserTypes.GetUserTypeAsync(createdUserType.Id));

            ex.StatusCode.Should().Be(404);
        }
Example #12
0
        public async Task ReplaceUserType()
        {
            var testClient      = TestClient.Create();
            var testDescription = $"{SdkPrefix}:{nameof(ReplaceUserType)} Test Description";
            var testDisplayName = $"{SdkPrefix}:{nameof(ReplaceUserType)} Test DisplayName";
            var testName        = $"{SdkPrefix}_{nameof(ReplaceUserType)}_TestUserType_{TestClient.RandomString(6)}";

            var createdUserType = await testClient.UserTypes.CreateUserTypeAsync(new UserType()
            {
                Description = testDescription,
                DisplayName = testDisplayName,
                Name        = testName,
            });

            try
            {
                createdUserType.Id.Should().NotBeNullOrEmpty();

                var replacedDescription = $"{createdUserType.Description} Repl"; // maximum length is 50
                var replacedDisplayName = $"{createdUserType.DisplayName} Repl";

                var replacedUserType = await testClient.UserTypes.ReplaceUserTypeAsync(
                    new UserType()
                {
                    Description = replacedDescription,
                    DisplayName = replacedDisplayName,
                    Name        = testName,
                }, createdUserType.Id);

                replacedUserType.Id.Should().Be(createdUserType.Id);
                replacedUserType.Description.Should().Be(replacedDescription);
                replacedUserType.DisplayName.Should().Be(replacedDisplayName);
                replacedUserType.Name.Should().Be(testName);

                var retrievedUserTypeForValidation = await testClient.UserTypes.GetUserTypeAsync(createdUserType.Id);

                retrievedUserTypeForValidation.Id.Should().Be(createdUserType.Id);
                retrievedUserTypeForValidation.Description.Should().Be(replacedDescription);
                retrievedUserTypeForValidation.DisplayName.Should().Be(replacedDisplayName);
            }
            finally
            {
                await testClient.UserTypes.DeleteUserTypeAsync(createdUserType.Id);
            }
        }
        public async Task RetrieveInlineHook()
        {
            var testClient         = TestClient.Create();
            var testInlineHookName = $"{SdkPrefix}:{nameof(RetrieveInlineHook)} Test Inline Hook Name ({TestClient.RandomString(6)})";

            var createdInlineHook = await testClient.InlineHooks.CreateInlineHookAsync(
                new InlineHook
            {
                Name    = testInlineHookName,
                Version = "1.0.0",
                Type    = "com.okta.oauth2.tokens.transform",
                Channel = new InlineHookChannel
                {
                    Type    = "HTTP",
                    Version = "1.0.0",
                    Config  = new InlineHookChannelConfig
                    {
                        Uri     = "https://www.example.com/inlineHook",
                        Headers = new List <IInlineHookChannelConfigHeaders>
                        {
                            new InlineHookChannelConfigHeaders
                            {
                                Key   = "X-Test-Header",
                                Value = "Test header value",
                            },
                        },
                        AuthScheme = new InlineHookChannelConfigAuthScheme
                        {
                            Type  = "HEADER",
                            Key   = "Authorization",
                            Value = "Test-Api-Key",
                        },
                    },
                },
            });

            try
            {
                createdInlineHook.Id.Should().NotBeNullOrEmpty();

                var retrievedInlineHook = await testClient.InlineHooks.GetInlineHookAsync(createdInlineHook.Id);

                retrievedInlineHook.Id.Should().NotBeNullOrEmpty();
                retrievedInlineHook.Id.Should().Be(createdInlineHook.Id);
                retrievedInlineHook.Name.Should().Be(testInlineHookName);
                retrievedInlineHook.Version.Should().Be("1.0.0");
                retrievedInlineHook.Type.Should().Be(InlineHookType.ComOktaOauth2TokensTransform);
                retrievedInlineHook.Channel.Should().NotBeNull();
                retrievedInlineHook.Channel.Config.Should().NotBeNull();
                retrievedInlineHook.Channel.Config.Uri.Should().Be("https://www.example.com/inlineHook");
            }
            finally
            {
                await testClient.InlineHooks.DeactivateInlineHookAsync(createdInlineHook.Id);

                await testClient.InlineHooks.DeleteInlineHookAsync(createdInlineHook.Id);
            }
        }
        public async Task ListAllInlineHooks()
        {
            var testClient         = TestClient.Create();
            var testInlineHookName = $"{SdkPrefix}:{nameof(ListAllInlineHooks)} Test Inline Hook Name ({TestClient.RandomString(6)})";

            var existingInlineHookIds = new HashSet <string>();

            await foreach (IInlineHook existingInlineHook in testClient.InlineHooks.ListInlineHooks())
            {
                existingInlineHookIds.Add(existingInlineHook.Id);
            }

            var testInlineHookIds = new HashSet <string>();

            for (int i = 0; i < 5; i++)
            {
                var createdInlineHook = await testClient.InlineHooks.CreateInlineHookAsync(new InlineHook
                {
                    Name    = $"{testInlineHookName} {i}",
                    Version = "1.0.0",
                    Type    = "com.okta.oauth2.tokens.transform",
                    Channel = new InlineHookChannel
                    {
                        Type    = "HTTP",
                        Version = "1.0.0",
                        Config  = new InlineHookChannelConfig
                        {
                            Uri     = "https://www.example.com/inlineHook",
                            Headers = new List <IInlineHookChannelConfigHeaders>
                            {
                                new InlineHookChannelConfigHeaders
                                {
                                    Key   = "X-Test-Header",
                                    Value = "Test header value",
                                },
                            },
                            AuthScheme = new InlineHookChannelConfigAuthScheme
                            {
                                Type  = "HEADER",
                                Key   = "Authorization",
                                Value = "Test-Api-Key",
                            },
                        },
                    },
                });

                testInlineHookIds.Add(createdInlineHook.Id);
            }

            try
            {
                var allInlineHookIds    = new HashSet <string>();
                var allInlineHooks      = testClient.InlineHooks.ListInlineHooks();
                int allInlineHooksCount = await allInlineHooks.CountAsync();

                allInlineHooksCount.Should().BeGreaterThan(0);
                allInlineHooksCount.Should().Be(existingInlineHookIds.Count + testInlineHookIds.Count);

                await foreach (var inlineHook in allInlineHooks)
                {
                    allInlineHookIds.Add(inlineHook.Id);
                }

                foreach (var testInlineHookId in testInlineHookIds)
                {
                    Assert.Contains(testInlineHookId, allInlineHookIds);
                }
            }
            finally
            {
                foreach (var testInlineHookId in testInlineHookIds)
                {
                    await testClient.InlineHooks.DeactivateInlineHookAsync(testInlineHookId);

                    await testClient.InlineHooks.DeleteInlineHookAsync(testInlineHookId);
                }
            }
        }
        public async Task DeleteInlineHook()
        {
            var testClient         = TestClient.Create();
            var testInlineHookName = $"{SdkPrefix}:{nameof(DeleteInlineHook)} Test Inline Hook Name ({TestClient.RandomString(6)})";

            var createdInlineHook = await testClient.InlineHooks.CreateInlineHookAsync(new InlineHook
            {
                Name    = testInlineHookName,
                Version = "1.0.0",
                Type    = "com.okta.oauth2.tokens.transform",
                Channel = new InlineHookChannel
                {
                    Type    = "HTTP",
                    Version = "1.0.0",
                    Config  = new InlineHookChannelConfig
                    {
                        Uri     = "https://www.example.com/inlineHook",
                        Headers = new List <IInlineHookChannelConfigHeaders>
                        {
                            new InlineHookChannelConfigHeaders
                            {
                                Key   = "X-Test-Header",
                                Value = "Test header value",
                            },
                        },
                        AuthScheme = new InlineHookChannelConfigAuthScheme
                        {
                            Type  = "HEADER",
                            Key   = "Authorization",
                            Value = "Test-Api-Key",
                        },
                    },
                },
            });

            createdInlineHook.Id.Should().NotBeNullOrEmpty();

            var retrievedEventHook = await testClient.InlineHooks.GetInlineHookAsync(createdInlineHook.Id);

            retrievedEventHook.Id.Should().Be(createdInlineHook.Id);

            await testClient.InlineHooks.DeactivateInlineHookAsync(createdInlineHook.Id);

            await testClient.InlineHooks.DeleteInlineHookAsync(createdInlineHook.Id);

            var ex = await Assert.ThrowsAsync <OktaApiException>(() =>
                                                                 testClient.EventHooks.GetEventHookAsync(createdInlineHook.Id));

            ex.StatusCode.Should().Be(404);
        }