SDK Management

If you wish to learn more about Tenants, check out our Tenants Overview doc.

Descope admins can create and update tenants either manually in the Descope console, using the Tenant Management APIs, or using the SDK as shown below.

Tenant management using the management SDK

Install SDK

Terminal
npm i --save @descope/node-sdk
Terminal
pip3 install descope
Terminal
go get github.com/descope/go-sdk
// Include the following in your `pom.xml` (for Maven)
<dependency>
    <artifactId>java-sdk</artifactId>
    <groupId>com.descope</groupId>
    <version>sdk-version</version> // Check https://github.com/descope/descope-java/releases for the latest versions
</dependency>
Terminal
gem install descope
Terminal
dotnet add package descope

Import and initialize Management SDK

import DescopeClient from '@descope/node-sdk';

const managementKey = "xxxx"

try{
    //  baseUrl="<URL>" // When initializing the Descope clientyou can also configure the baseUrl ex: https://auth.company.com  - this is useful when you utilize a custom domain within your Descope project.
    const descopeClient = DescopeClient({ projectId: '__ProjectID__', managementKey: managementKey });
} catch (error) {
    // handle the error
    console.log("failed to initialize: " + error)
}
from descope import (
    REFRESH_SESSION_TOKEN_NAME,
    SESSION_TOKEN_NAME,
    AuthException,
    DeliveryMethod,
    DescopeClient,
    AssociatedTenant,
    RoleMapping,
    AttributeMapping
)

management_key = "xxxx"

try:
    # You can configure the baseURL by setting the env variable Ex: export DESCOPE_BASE_URI="https://auth.company.com  - this is useful when you utilize a custom domain within your Descope project."
    descope_client = DescopeClient(project_id='__ProjectID__', management_key=management_key)
except Exception as error:
    # handle the error
    print ("failed to initialize. Error:")
    print (error)
import "github.com/descope/go-sdk/descope"
import "github.com/descope/go-sdk/descope/client"
import "fmt"

// Utilizing the context package allows for the transmission of context capabilities like cancellation
//      signals during the function call. In cases where context is absent, the context.Background()
//      function serves as a viable alternative.
//      Utilizing context within the Descope GO SDK is supported within versions 1.6.0 and higher.
import (
	"context"
)

managementKey = "xxxx"

// DescopeBaseURL // within the client.Config, you can also configure the baseUrl ex: https://auth.company.com  - this is useful when you utilize a custom domain within your Descope project.
descopeClient, err := client.NewWithConfig(&client.Config{ProjectID:"__ProjectID__", managementKey:managementKey})
if err != nil {
    // handle the error
    log.Println("failed to initialize: " + err.Error())
}
import com.descope.client;

// Initialized after setting the DESCOPE_PROJECT_ID env var (and optionally DESCOPE_MANAGEMENT_KEY)
var descopeClient = new DescopeClient();

// ** Or directly **
var descopeClient = new DescopeClient(Config.builder()
        .projectId("__ProjectID__")
        .managementKey("management-key")
        .build());
require 'descope'

descope_client = Descope::Client.new(
  {
    project_id: '__ProjectID__',
    management_key: 'management_key'
  }
)
// appsettings.json

{
  "Descope": {
    "ProjectId": "your-project-id",
    "ManagementKey": "your-management-key"
  }
}

// Program.cs

using Descope;
using Microsoft.Extensions.Configuration;

// ... In your setup code
var config = new ConfigurationBuilder()
  .AddJsonFile("appsettings.json")
  .Build();

var descopeProjectId = config["Descope:ProjectId"];
var descopeManagementKey = config["Descope:ManagementKey"];

var descopeConfig = new DescopeConfig(projectId: descopeProjectId);
var descopeClient = new DescopeClient(descopeConfig)
{
    ManagementKey = descopeManagementKey,
};

Load All tenants

Use the code below to load all existing tenants within the project

let resp = await descopeClient.management.tenant.loadAll();
if (!resp.ok) {
  console.log("Unable to load tenants.")
  console.log("Status Code: " + resp.code)
  console.log("Error Code: " + resp.error.errorCode)
  console.log("Error Description: " + resp.error.errorDescription)
  console.log("Error Message: " + resp.error.errorMessage)
}
else {
  console.log("Successfully loaded tenants:")
  console.log(resp.data)
}
try:
    resp = descope_client.mgmt.tenant.load_all()
    print ("Successfully loaded tenants:")
    print(json.dumps(resp, indent=2))
except AuthException as error:
    print ("Unable to load tenants.")
    print ("Status Code: " + str(error.status_code))
    print ("Error: " + str(error.error_message))
// Args:
//   ctx: context.Context - Application context for the transmission of context capabilities like
//        cancellation signals during the function call. In cases where context is absent, the context.Background()
//        function serves as a viable alternative.
//        Utilizing context within the Descope GO SDK is supported within versions 1.6.0 and higher.
ctx := context.Background()

res, err := descopeClient.Management.Tenant().LoadAll(ctx)
if  (err != nil){
  fmt.Println("Unable to load tenants: ", err)
} else {
  fmt.Println("Successfully loaded tenants: ")
  for _, t := range res {
    fmt.Println(t)
  }
}
TenantService ts = descopeClient.getManagementServices().getTenantService();
// Load all tenants
try {
    List<Tenant> tenants = ts.loadAll();
    for (Tenant t : tenants) {
        // Do something
    }
} catch (DescopeException de) {
    // Handle the error
}
try
{
    var tenants = await descopeClient.Management.Tenant.LoadAll();
    foreach (var tenant in tenants)
    {
        // do something
    }
}
catch (DescopeException ex)
{
    // Handle the error
}

Load Tenant by ID

This function allows for you to load a specific tenant based on the tenant's ID.

// Args:
//  id (String): The ID of the tenant which you want to load
const id = "xxxx"

let resp = await descopeClient.management.tenant.load(id);
if (!resp.ok) {
  console.log("Failed to load tenant.")
  console.log("Status Code: " + resp.code)
  console.log("Error Code: " + resp.error.errorCode)
  console.log("Error Description: " + resp.error.errorDescription)
  console.log("Error Message: " + resp.error.errorMessage)
}
else {
  console.log("Successfully loaded tenant.")
  console.log(resp.data)
}
# Args:
#  id (String): The ID of the tenant which you want to load
id = "xxxx"

try:
    resp = descope_client.mgmt.tenant.load(id=id)
    print("Successfully loaded tenant")
    print(json.dumps(resp, indent=4))
except AuthException as error:
    print ("Failed to load tenant")
    print ("Status Code: " + str(error.status_code))
    print ("Error: " + str(error.error_message))
// Args:
//  ctx: context.Context - Application context for the transmission of context capabilities like
//        cancellation signals during the function call. In cases where context is absent, the context.Background()
//        function serves as a viable alternative.
//        Utilizing context within the Descope GO SDK is supported within versions 1.6.0 and higher.
ctx := context.Background()
// 	id (String): The ID of the tenant which you want to load
id := "xxxx"

res, err := descopeClient.Management.Tenant().Load(ctx, id)
if  (err != nil){
  fmt.Println("Unable to load tenant: ", err)
} else {
  fmt.Println("Successfully loaded tenant: ")
  fmt.Println(res)
}
TenantService ts = descopeClient.getManagementServices().getTenantService();
try {
    ts.load("my-custom-id");
} catch (DescopeException de) {
    // Handle the error
}
// Args:
//   tenantID (string): The ID of the tenant to load.
var tenantID = "tenant-id";

try
{
    var tenantRes = await descopeClient.Management.Tenant.LoadById(id: tenantID);
}
catch (DescopeException ex)
{
    // Handle the error
}

Search Tenants

This function allows for you to search Descope tenants by ID, name, self service provisioning domain, and custom attributes.

// Args:
//  ids (String[]): Array of tenant IDs to search for.
const ids = ["TestTenant"]
//  names (String[]): Array of tenant names to search for.
const names = ["TestTenant"]
//  selfProvisioningDomains (String[]): Array of self service provisioning domains to search for.
const selfProvisioningDomains = ["example.com", "company.com"]
//  customAttributes (String[]): Array of self service provisioning domains to search for.
const customAttributes = {"mycustomattribute": "Test"}

// When searching based on one of these items or a few of these items, leave the applicable items you are not searching for to null.
let resp = await descopeClient.management.tenant.searchAll(ids, names, selfProvisioningDomains, customAttributes);

if (!resp.ok) {
  console.log("Failed to search tenants.")
  console.log("Status Code: " + resp.code)
  console.log("Error Code: " + resp.error.errorCode)
  console.log("Error Description: " + resp.error.errorDescription)
  console.log("Error Message: " + resp.error.errorMessage)
}
else {
  console.log("Successfully searched tenants.")
  resp.data.forEach((tenant) => {
    console.log(tenant)
  });
}
# Args:
#  ids (String[]): Array of tenant IDs to search for.
ids = ["TestTenant"]
#  names (String[]): Array of tenant names to search for.
names = ["TestTenant"]
#  selfProvisioningDomains (String[]): Array of self service provisioning domains to search for.
self_provisioning_domains = ["example.com", "company.com"]
#  customAttributes (String[]): Array of self service provisioning domains to search for.
custom_attributes = {"mycustomattribute": "Test"}

# When searching based on one of these items or a few of these items, leave the applicable items you are not searching for to null.
try:
    resp = descope_client.mgmt.tenant.search_all(ids=ids, names=names, self_provisioning_domains=self_provisioning_domains, custom_attributes=custom_attributes)
    print("Successfully searched tenants")
    print(json.dumps(resp, indent=4))
except AuthException as error:
    print ("Failed to search tenants")
    print ("Status Code: " + str(error.status_code))
    print ("Error: " + str(error.error_message))
// Args:
//  ctx: context.Context - Application context for the transmission of context capabilities like
//        cancellation signals during the function call. In cases where context is absent, the context.Background()
//        function serves as a viable alternative.
//        Utilizing context within the Descope GO SDK is supported within versions 1.6.0 and higher.
ctx := context.Background()
//  searchOptions (&descope.TenantSearchOptions{}): Search options for your tenant search
searchOptions := &descope.TenantSearchOptions{}
searchOptions.IDs = []string{"TestTenant"}
searchOptions.Names = []string{"TestTenant"}
searchOptions.SelfProvisioningDomains = []string{"example.com", "company.com"}
searchOptions.CustomAttributes = map[string]any{"mycustomattribute": "Test"}

res, err := descopeClient.Management.Tenant().SearchAll(ctx, searchOptions)
if  (err != nil){
  fmt.Println("Unable to search tenants: ", err)
} else {
  fmt.Println("Successfully searched tenants: ")
  for _, t := range res {
    fmt.Println(t)
  }
}
TenantService ts = descopeClient.getManagementServices().getTenantService();

try {
    List<Tenant> tenants = ts.searchAll(TenantSearchRequest.builder()
            .ids(Arrays.asList("TestTenant"))
            .names(Arrays.asList("TestTenant"))
            .customAttributes(Map.of("mycustomattribute", "Test"))
            .selfProvisioningDomains(Arrays.asList("example.com", "company.com")));
    for (Tenant t : tenants) {
        // Do something
    }
} catch (DescopeException de) {
    // Handle the error
}
// Args:
//   searchOptions (TenantSearchOptions?): Fine‑tune filters.
var searchOptions = new TenantSearchOptions
{
    Ids = new List<string> {"my-custom-id"},
    Names = new List<string> { "My Tenant" },
    SelfProvisioningDomains = new List<string> {"domain.com", "company.com"},
    CustomAttributes = new Dictionary<string, object> {{ "mycustomattribute": "Test" }},
};

try
{
    var tenantList = await descopeClient.Management.Tenant.SearchAll(options: searchOptions);
    foreach (var tenant in tenants)
    {
        // do something
    }
}
catch (DescopeException ex)
{
    // Handle the error
}

Create Tenant

At the time of creation, the tenant must be given a name and a tenant-id. If you don't provide a tenant-id, a tenant-id is automatically generated. The tenant-id is used for sign-up/sign-in and other management operations later. In addition, you can also set domains for the tenant. The domain is used to automatically assign the end-user to a tenant at the time of sign-up and sign-in. The tenant name must be unique per project. The tenant ID is generated automatically for the tenant when not provided.

// There are two ways to create a tenant via SDK. createWithId (which will assign the given id) and create (which will automatically generate the id). Examples below:
// createWithId: Create a new tenant with a given name and tenant id.
// ==================================================================
// Args:
//    name (str): The tenant's name
var name = "TestTenantCreateWithId"
//    id (str): The tenant's id.
var id = "TestConfiguredId"
//    selfProvisioningDomains (List[str]): An optional list of domains that are associated with this tenant. Users authenticating from these domains will be associated with this tenant.
var selfProvisioningDomains = ["TestDomain1.com", "TestDomain2.com"]
//   customAttributes (dict): Optional, set the different custom attributes values of the keys that were previously configured in Descope console app
const customAttributes = {"attribute1": "Value 1", "attribute2": "Value 2"}

let resp = await descopeClient.management.tenant.createWithId(id, name, selfProvisioningDomains, customAttributes)
if (!resp.ok) {
  console.log(resp)
  console.log("Unable to create tenant.")
  console.log("Status Code: " + resp.code)
  console.log("Error Code: " + resp.error.errorCode)
  console.log("Error Description: " + resp.error.errorDescription)
  console.log("Error Message: " + resp.error.errorMessage)
}
else {
  console.log("Successfully created tenant.")
  console.log(resp.data)
}

// Create: Create a new tenant with the given name. The id will be automatically generated and returned.
// ==================================================================
// Args:
//    name (str): The tenant's name
name = "TestTenantCreateGeneratedId"
//    selfProvisioningDomains (List[str]): An optional list of domains that are associated with this tenant. Users authenticating from these domains will be associated with this tenant.
selfProvisioningDomains = ["TestDomain3.com", "TestDomain4.com"]
//   customAttributes (dict): Optional, set the different custom attributes values of the keys that were previously configured in Descope console app
const customAttributes = {"attribute1": "Value 1", "attribute2": "Value 2"}

resp = await descopeClient.management.tenant.create(name, selfProvisioningDomains, customAttributes)
if (!resp.ok) {
  console.log("Unable to create tenant.")
  console.log("Status Code: " + resp.code)
  console.log("Error Code: " + resp.error.errorCode)
  console.log("Error Description: " + resp.error.errorDescription)
  console.log("Error Message: " + resp.error.errorMessage)
}
else {
  console.log("Successfully created tenant.")
  console.log(resp.data)
}
# Create a new tenant with the given name. Tenant IDs are provisioned automatically, but can be provided explicitly if needed. Both the name and ID must be unique per project.
# Args:
#   name (str): The tenant's name
name = "TestTenantCreateWithId"
#   id (str): Optional tenant ID. If not provided, it will be auto assigned.
id = "TestTenantCreateWithId"
#   self_provisioning_domains (List[str]): An optional list of domains that are associated with this tenant. Users authenticating from these domains will be associated with this tenant.
self_provisioning_domains = ["TestDomain1.com", "TestDomain2.com"]
#   custom_attributes (dict): Optional, set the different custom attributes values of the keys that were previously configured in Descope console app
custom_attributes = {"attribute1": "Value 1", "attribute2": "Value 2"}

try:
  resp = descope_client.mgmt.tenant.create(name=name, id=id, self_provisioning_domains=self_provisioning_domains, custom_attributes=custom_attributes)
  print ("Successfully created tenant.")
  print(json.dumps(resp, indent=2))
except AuthException as error:
  print ("Unable to create tenant.")
  print ("Status Code: " + str(error.status_code))
  print ("Error: " + str(error.error_message))
// There are two ways to create a tenant via SDK. CreateWithID (which will assign the given id) and Create (which will automatically generate the id). Examples below:
// CreateWithID: Create a new tenant with a given name and tenant id.
// ==================================================================
// Args:
//    ctx: context.Context - Application context for the transmission of context capabilities like
//        cancellation signals during the function call. In cases where context is absent, the context.Background()
//        function serves as a viable alternative.
//        Utilizing context within the Descope GO SDK is supported within versions 1.6.0 and higher.
ctx := context.Background()
//    tenantRequest (&descope.TenantRequest{}): Tenant options for creation
tenantRequest := &descope.TenantRequest{}
tenantRequest.Name = []string{"TestTenant"}
tenantRequest.SelfProvisioningDomains = []string{"example.com", "company.com"}
tenantRequest.CustomAttributes = map[string]any{"mycustomattribute": "Test"}
//    id (str): The tenant's id.
id := "TestConfiguredId"


err := descopeClient.Management.Tenant().CreateWithID(ctx, id, tenantRequest)
if  (err != nil){
  fmt.Println("Unable to create tenant with specified ID: ", err)
} else {
  fmt.Println("Successfully created tenant with specified ID")
}

// Create: Create a new tenant with the given name. The id will be automatically generated and returned.
// ==================================================================
// Args:
//    ctx: context.Context - Application context for the transmission of context capabilities like
//        cancellation signals during the function call. In cases where context is absent, the context.Background()
//        function serves as a viable alternative.
//        Utilizing context within the Descope GO SDK is supported within versions 1.6.0 and higher.
ctx := context.Background()
//    tenantRequest (&descope.TenantRequest{}): Tenant options for creation
tenantRequest := &descope.TenantRequest{}
tenantRequest.Name = []string{"TestTenant"}
tenantRequest.SelfProvisioningDomains = []string{"example.com", "company.com"}
tenantRequest.CustomAttributes = map[string]any{"mycustomattribute": "Test"}

tenantID, err := descopeClient.Management.Tenant().Create(ctx, tenantRequest)
if  (err != nil){
  fmt.Println("Unable to create tenant: ", err)
} else {
  fmt.Println("Successfully created tenant. The automatically generated ID is: ", tenantID)
}
TenantService ts = descopeClient.getManagementServices().getTenantService();
// The self provisioning domains or optional. If given they'll be used to associate
// Users logging in to this tenant
try {
    ts.create("My Tenant", Arrays.asList("domain.com"), new HashMap<String, Object>() {{
        put("custom-attribute-1", "custom-value1");
        put("custom-attribute-2", "custom-value2");
    }});
} catch (DescopeException de) {
    // Handle the error
}

// You can optionally set your own ID when creating a tenant
try {
    ts.createWithId("my-custom-id", "My Tenant", Arrays.asList("domain.com"), new HashMap<String, Object>() {{
        put("custom-attribute-1", "custom-value1");
        put("custom-attribute-2", "custom-value2");
    }});
} catch (DescopeException de) {
    // Handle the error
}
// Args:
//   tenantOpts (TenantOptions): Configuration for the new tenant (name required).
var tenantOpts = new TenantOptions("name")
{
    SelfProvisioningDomains = new List<string> { "domain" },
    CustomAttributes = new Dictionary<string, object> { { "mycustomattribute", "test" } },
};
//   tenantID (string?): Optional custom ID. Otherwise, it will be auto‑generated by Descope.
string? tenantID = "my-tenant-id";

try
{
    var newTenantId = await descopeClient.Management.Tenant.Create(options: tenantOpts, id: tenantID);
}
catch (DescopeException ex)
{
    // Handle the error
}

Update Tenant

Use the code below to update an existing tenant with the given name and domains. All parameters are used as overrides to the existing tenant. Empty fields will override populated fields.

// Args:
//    id (str): The tenant's id.
var id = "xxxxxx"
//    name (str): The tenant's name
var name = "Test Updated Name"
//    selfProvisioningDomains (List[str]): An optional list of domains that are associated with this tenant. Users authenticating from these domains will be associated with this tenant. If changed, it will be the new list of self provisioned domains.
var selfProvisioningDomains = ["TestUpdatedDomain1.com", "TestUpdatedDomain2.com"]
//   customAttributes (dict): Optional, set the different custom attributes values of the keys that were previously configured in Descope console app
const customAttributes = {"attribute1": "Value 1", "attribute2": "Value 2"}

const resp = await descopeClient.management.tenant.update(id, name, selfProvisioningDomains, customAttributes);
if (!resp.ok) {
  console.log(resp)
  console.log("Failed to update tenant.")
  console.log("Status Code: " + resp.code)
  console.log("Error Code: " + resp.error.errorCode)
  console.log("Error Description: " + resp.error.errorDescription)
  console.log("Error Message: " + resp.error.errorMessage)
}
else {
  console.log("Successfully update tenant.")
  console.log(resp.data)
}
# Args:
#   id (str): The ID of the tenant to update.
id = "xxxxxx"
#   name (str): The tenant's name, if changed, it will be the new name.
name = "Test Updated Name"
#   self_provisioning_domains (List[str]): An optional list of domains that are associated with this tenant. Users authenticating from these domains will be associated with this tenant. If changed, it will be the new list of self provisioned domains.
self_provisioning_domains = ["TestUpdatedDomain1.com", "TestUpdatedDomain2.com"]
#   custom_attributes (dict): Optional, set the different custom attributes values of the keys that were previously configured in Descope console app
custom_attributes = {"attribute1": "Value 1", "attribute2": "Value 2"}

try:
  resp = descope_client.mgmt.tenant.update(id=id, name=name, self_provisioning_domains=self_provisioning_domains, custom_attributes=custom_attributes)
  print ("Successfully updated tenant.")
except AuthException as error:
  print ("Unable to update tenant.")
  print ("Status Code: " + str(error.status_code))
  print ("Error: " + str(error.error_message))
// Args:
//    ctx: context.Context - Application context for the transmission of context capabilities like
//        cancellation signals during the function call. In cases where context is absent, the context.Background()
//        function serves as a viable alternative.
//        Utilizing context within the Descope GO SDK is supported within versions 1.6.0 and higher.
ctx := context.Background()
//    id (str): The id of the tenant you want to update.
id := "xxxxxx"
//    tenantRequest (&descope.TenantRequest{}): Tenant options for update
tenantRequest := &descope.TenantRequest{}
tenantRequest.Name = []string{"TestTenant"}
tenantRequest.SelfProvisioningDomains = []string{"example.com", "company.com"}
tenantRequest.CustomAttributes = map[string]any{"mycustomattribute": "Test"}

err := descopeClient.Management.Tenant().Update(ctx, id, tenantRequest)
if  (err != nil){
  fmt.Println("Unable to update tenant: ", err)
} else {
  fmt.Println("Successfully updated tenant")
}
TenantService ts = descopeClient.getManagementServices().getTenantService();
// Update will override all fields as is. Use carefully.
try {
    ts.update("my-custom-id", "My Tenant", Arrays.asList("domain.com", "another-domain.com"), new HashMap<String, Object>() {{
                put("custom-attribute-1", "custom-value1");
                put("custom-attribute-2", "custom-value2");
            }});
} catch (DescopeException de) {
    // Handle the error
}
// Args:
//   tenantID (string): The ID of the tenant to update.
var tenantID = "tenant-id";
//   tenantOpts (TenantOptions): New details to set (all fields override existing).
var tenantOpts = new TenantOptions
{
    SelfProvisioningDomains = new List<string> { "domain" },
    CustomAttributes = new Dictionary<string, object> { { "mycustomattribute", "test" } },
};

try
{
    await descopeClient.Management.Tenant.Update(id: tenantID, options: tenantOpts);
}
catch (DescopeException ex)
{
    // Handle the error
}

Delete Tenant

Use the code below to delete an existing tenant. Please note that this action is irreversible.

// Args:
//    id (str): The tenant's id.
var id = "xxxxxx"
//    cascade (boolean): Pass true to cascade value, in case you want to delete all users/keys associated only with this tenant
var cascade = false

let resp = await descopeClient.management.tenant.delete(id, cascade);
if (!resp.ok) {
  console.log(resp)
  console.log("Unable to delete tenant.")
  console.log("Status Code: " + resp.code)
  console.log("Error Code: " + resp.error.errorCode)
  console.log("Error Description: " + resp.error.errorDescription)
  console.log("Error Message: " + resp.error.errorMessage)
}
else {
  console.log("Successfully deleted tenant.")
  console.log(resp.data)
}
# Args:
#   id (str): The id of the tenant to be deleted.
id = "xxxxxx"
#  cascade (boolean): Pass true to cascade value, in case you want to delete all users/keys associated only with this tenant
cascade = False

try:
  resp = descope_client.mgmt.tenant.delete(id=id, cascade=cascade)
  print("Successfully deleted tenant.")
except AuthException as error:
  print ("Unable to delete tenant.")
  print ("Status Code: " + str(error.status_code))
  print ("Error: " + str(error.error_message))
// Args: 
//    ctx: context.Context - Application context for the transmission of context capabilities like
//        cancellation signals during the function call. In cases where context is absent, the context.Background()
//        function serves as a viable alternative.
//        Utilizing context within the Descope GO SDK is supported within versions 1.6.0 and higher.
ctx := context.Background()
//    id (str): The id of the tenant you want to delete.
id := "xxxxxx"
//    cascade (boolean): Pass true to cascade value, in case you want to delete all users/keys associated only with this tenant
cascade := false

err := descopeClient.Management.Tenant().Delete(ctx, id, cascade)
if  (err != nil){
  fmt.Println("Unable to delete tenant: ", err)
} else {
  fmt.Println("Successfully deleted tenant")
}
TenantService ts = descopeClient.getManagementServices().getTenantService();
// Tenant deletion cannot be undone. Use carefully.
try {
    ts.delete("my-custom-id");
} catch (DescopeException de) {
    // Handle the error
}
// Args:
//   tenantID (string): The ID of the tenant to delete (irreversible).
var tenantID = "tenant-id";

try
{
    await descopeClient.Management.Tenant.Delete(id: tenantID);
}
catch (DescopeException ex)
{
    // Handle the error
}

Update Tenant Password Policy

Use the code below to update password policy for your tenant.

// Args:
  //tenantId (str): The tenant Id whose password policy has to be updated.
  //enabled (boolean): To enable 
  //minLength (int) : minimum passwords length
  //lowercase (boolean): Requires atleast one lowercase letter
  //uppercase (boolean): Requires atleast one uppercase letter
  //number (boolean): Requires atleast one number
  //nonAlphaNumeric (boolean) : Requies at least one non-alphanumeric character
  //expiration (boolean): Enable password expiration
  //expirationWeeks (int): Password expiration period in weeks
  //reuse (boolean): Enable/Disable prevent password reuse
  //reuseAmount (int): Number of passwords to remember
  //lock (boolean) : Enable/Disable account locking
  //lockAttempts (int) : Lock account after this number of attempts

const tenantId = "xxxx"
const policysetting = {
  enabled: true,
  minLength: 8,
  expiration: true,
  expirationWeeks: 4,
  lock: true,
  lockAttempts: 5,
  reuse: true,
  reuseAmount: 6,
  lowercase: true,
  uppercase: false,
  number: true,
  nonAlphaNumeric: false,

}

const resp = await descopeClient.management.password.configureSettings(tenantId, policysetting);
if (!resp.ok) {
  console.log("Failed to update access key.")
  console.log("Status Code: " + resp.code)
  console.log("Error Code: " + resp.error.errorCode)
  console.log("Error Description: " + resp.error.errorDescription)
  console.log("Error Message: " + resp.error.errorMessage)
}
else {
  console.log("Successfully updated password policy.")
  console.log(resp.data)
}
// Args:
//    ctx: context.Context - Application context for the transmission of context capabilities like
//        cancellation signals during the function call. In cases where context is absent, the context.Background()
//        function serves as a viable alternative.
//        Utilizing context within the Descope GO SDK is supported within versions 1.6.0 and higher.
ctx := context.Background()
tenantId = "xxxx"
//    policy (descope.PasswordSettings): Policy object to update password policy.
policy := &descope.PasswordSettings{
    Enabled:         true,
    MinLength:       8,
    Lowercase:       true,
    Uppercase:       true,
    Number:          true,
    NonAlphanumeric: true,
    Expiration:      true,
    ExpirationWeeks: 3,
    Reuse:           true,
    ReuseAmount:     3,
    Lock:            true,
    LockAttempts:    4,
}
resp, err := descopeClient.Management.Password().ConfigureSettings(ctx, tenantId, policy)
if (err != nil){
  fmt.Println("Failed to update password policy: ", err)
} else {
  fmt.Println("Successfully updated password policy", resp)
}
# settings is a hash storing key value pair for password policy settings for the required tenant ID

settings = {"minLength" => 10}
descope_client.update_password_settings(settings)
// Args:
//   tenantID (string?): Optional tenant ID. Setting null will configure project‑level settings.
string? tenantID = "tenant-id"; 
//   newSettings (PasswordSettings): Configuration to apply (all fields override existing).
var newSettings = new PasswordSettings
{
    Enabled            = true,
    MinLength          = 8,
    Lowercase          = true,
    Uppercase          = true,
    Number             = true,
    NonAlphanumeric    = true,
    Expiration         = true,
    ExpirationWeeks    = 3,
    Reuse              = true,
    ReuseAmount        = 3,
    Lock               = true,
    LockAttempts       = 5,
};

try
{
    // Load current password settings 
    var currSettings = await descopeClient.Management.Password.GetSettings(tenantID);

    // Configure (override) password settings 
    await descopeClient.Management.Password.ConfigureSettings(
        settings : newSettings,
        tenantId : tenantID);
}
catch (DescopeException ex)
{
    // Handle the error
}

Get and Update Tenant Settings

Use the getSettings and configureSettings functions as shown below to access and update settings for your tenant, based on the tenant ID.

// Args:
//  id (String): The ID of the tenant for which you want to access and update settings
const id = "xxxx"

// Load tenant settings by id
const tenantSettings = await descopeClient.management.tenant.getSettings(id);

// Update will override all fields as is. Use carefully.
await descopeClient.management.tenant.configureSettings(id, {
  domains: ['domain1.com'],
  selfProvisioningDomains: ['domain1.com'],
  sessionSettingsEnabled: true,
  refreshTokenExpiration: 12,
  refreshTokenExpirationUnit: 'days',
  sessionTokenExpiration: 10,
  sessionTokenExpirationUnit: 'minutes',
  enableInactivity: true,
  JITDisabled: false,
  InactivityTime: 10,
  InactivityTimeUnit: 'minutes',
});
// Args:
//  ctx: context.Context - Application context for the transmission of context capabilities like
//        cancellation signals during the function call. In cases where context is absent, the context.Background()
//        function serves as a viable alternative.
//        Utilizing context within the Descope GO SDK is supported within versions 1.6.0 and higher.
ctx := context.Background()
// 	id (String): The ID of the tenant for which you want to access and update settings
id := "xxxx"

// Load tenant settings by a tenant id
settings, err := descopeClient.Management.Tenant().GetSettings(ctx)

// Configure desired settings 
settingsRequest := &descope.TenantSettings{}
settingsRequest.SelfProvisioningDomains = []string{"domain.com", "company.com"}
settingsRequest.RefreshTokenExpiration = 30
settingsRequest.RefreshTokenExpirationUnit = "days"
settingsRequest.SessionTokenExpiration = 30
settingsRequest.SessionTokenExpirationUnit = "minutes"
settingsRequest.EnableInactivity = true
settingsRequest.InactivityTime = 2
settingsRequest.InactivityTimeUnit = "days"

// Update the tenant settings
err := descopeClient.Management.Tenant().ConfigureSettings(ctx, id, settingsRequest)
Was this helpful?

On this page