public async Task UpdateUserProfileSchemaProperty() { var testClient = TestClient.Create(); var userSchema = await testClient.UserSchemas.GetUserSchemaAsync("default"); var guid = Guid.NewGuid(); // Add custom attribute var customAttributeDetails = new UserSchemaAttribute() { Title = "Twitter username", Type = "string", Description = guid.ToString(), MinLength = 1, MaxLength = 20, Permissions = new List <IUserSchemaAttributePermission> { new UserSchemaAttributePermission { Action = "READ_WRITE", Principal = "SELF", }, }, }; var customAttribute = new Resource(); customAttribute["twitterUserName"] = customAttributeDetails; userSchema.Definitions.Custom.Properties = customAttribute; var updatedUserSchema = await testClient.UserSchemas.UpdateUserProfileAsync(userSchema, "default"); var retrievedCustomAttribute = updatedUserSchema.Definitions.Custom.Properties.GetProperty <UserSchemaAttribute>("twitterUserName"); retrievedCustomAttribute.Title.Should().Be("Twitter username"); retrievedCustomAttribute.Type.Should().Be(UserSchemaAttributeType.String); retrievedCustomAttribute.Description.Should().Be(guid.ToString()); retrievedCustomAttribute.Required.Should().BeNull(); retrievedCustomAttribute.MinLength.Should().Be(1); retrievedCustomAttribute.MaxLength.Should().Be(20); retrievedCustomAttribute.Permissions.FirstOrDefault().Principal.Should().Be("SELF"); retrievedCustomAttribute.Permissions.FirstOrDefault().Action.Should().Be("READ_WRITE"); // Wait for job to be finished Thread.Sleep(3000); // Remove custom attribute customAttribute["twitterUserName"] = null; updatedUserSchema.Definitions.Custom.Properties = customAttribute; updatedUserSchema = await testClient.UserSchemas.UpdateUserProfileAsync(updatedUserSchema, "default"); updatedUserSchema.Definitions.Custom.Properties.GetProperty <UserSchemaAttribute>("twitterUserName").Should().BeNull(); }
public async Task UpdateApplicationUserSchema() { var rawResponse = @" { ""id"": ""https://${yourOktaDomain}/meta/schemas/apps/0oa25gejWwdXNnFH90g4/default"", ""$schema"": ""http://json-schema.org/draft-04/schema#"", ""name"": ""Example App"", ""title"": ""Example App User"", ""lastUpdated"": ""2017-07-18T23:18:43.000Z"", ""created"": ""2017-07-18T22:35:30.000Z"", ""definitions"": { ""base"": { ""id"": ""#base"", ""type"": ""object"", ""properties"": { ""userName"": { ""title"": ""Username"", ""type"": ""string"", ""required"": true, ""scope"": ""NONE"", ""maxLength"": 100 } }, ""required"": [ ""userName"" ] }, ""custom"": { ""id"": ""#custom"", ""type"": ""object"", ""properties"": { ""twitterUserName"": { ""title"": ""Twitter username"", ""description"": ""User's username for twitter.com"", ""type"": ""string"", ""scope"": ""NONE"", ""minLength"": 1, ""maxLength"": 20 } }, ""required"": [] } }, ""type"": ""object"", ""properties"": { ""profile"": { ""allOf"": [ { ""$ref"": ""#/definitions/base"" }, { ""$ref"": ""#/definitions/custom"" } ] } } }"; var mockRequestExecutor = new MockedStringRequestExecutor(rawResponse); var client = new TestableOktaClient(mockRequestExecutor); // Add custom attribute var customAttributeDetails = new UserSchemaAttribute() { Title = "Twitter username", Type = "string", Description = "User's username for twitter.com", MinLength = 1, MaxLength = 20, }; var customAttribute = new Resource(); customAttribute["twitterUserName"] = customAttributeDetails; var userSchema = new UserSchema(); userSchema.Definitions = new UserSchemaDefinitions { Custom = new UserSchemaPublic { Properties = customAttribute, }, }; var updatedUserSchema = await client.UserSchemas.UpdateApplicationUserProfileAsync(userSchema, "foo"); var retrievedCustomAttribute = updatedUserSchema.Definitions.Custom.Properties.GetProperty <UserSchemaAttribute>("twitterUserName"); retrievedCustomAttribute.Title.Should().Be("Twitter username"); retrievedCustomAttribute.Type.Should().Be(UserSchemaAttributeType.String); retrievedCustomAttribute.Description.Should().Be("User's username for twitter.com"); retrievedCustomAttribute.Required.Should().BeNull(); retrievedCustomAttribute.MinLength.Should().Be(1); retrievedCustomAttribute.MaxLength.Should().Be(20); mockRequestExecutor.ReceivedHref.Should().StartWith("/api/v1/meta/schemas/apps/foo/default"); }