Skip to content

Commit

Permalink
Added tenant custom attributes and search to readme
Browse files Browse the repository at this point in the history
  • Loading branch information
chris4490 committed Dec 21, 2023
1 parent 9c190f4 commit 64f8611
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -578,13 +578,21 @@ You can create, update, delete or load tenants:
```go
// The self provisioning domains or optional. If given they'll be used to associate
// Users logging in to this tenant
err := descopeClient.Management.Tenant().Create(context.Background(), "My Tenant", []string{"domain.com"})

// Creating and updating tenants takes the &descope.TenantRequest type. This is an example of a &descope.TenantRequest
tenantRequest := &descope.TenantRequest{}
tenantRequest.Name = []string{"My Tenant"}
tenantRequest.SelfProvisioningDomains = []string{"domain.com"}
tenantRequest.CustomAttributes = map[string]any{"mycustomattribute": "Test"}

// Create tenant
err := descopeClient.Management.Tenant().Create(context.Background(), "My Tenant", tenantRequest)

// You can optionally set your own ID when creating a tenant
err := descopeClient.Management.Tenant().CreateWithID(context.Background(), "my-custom-id", "My Tenant", []string{"domain.com"})
err := descopeClient.Management.Tenant().CreateWithID(context.Background(), "my-custom-id", "My Tenant", tenantRequest)

// Update will override all fields as is. Use carefully.
err := descopeClient.Management.Tenant().Update(context.Background(), "my-custom-id", "My Tenant", []string{"domain.com", "another-domain.com"})
err := descopeClient.Management.Tenant().Update(context.Background(), "my-custom-id", "My Tenant", tenantRequest)

// Tenant deletion cannot be undone. Use carefully.
err := descopeClient.Management.Tenant().Delete(context.Background(), "my-custom-id")
Expand All @@ -599,6 +607,19 @@ if err == nil {
// Do something
}
}

// Search tenants - takes the &descope.TenantSearchOptions type. This is an example of a &descope.TenantSearchOptions
searchOptions := &descope.TenantSearchOptions{}
searchOptions.IDs = []string{"my-custom-id"}
searchOptions.Names = []string{"My Tenant"}
searchOptions.SelfProvisioningDomains = []string{"domain.com", "company.com"}
searchOptions.CustomAttributes = map[string]any{"mycustomattribute": "Test"}
res, err := descopeClient.Management.Tenant().SearchAll(context.Background(), searchOptions)
if err == nil {
for _, tenant := range res {
// Do something
}
}
```

### Manage Users
Expand Down

0 comments on commit 64f8611

Please sign in to comment.