Managing Themes

Manage your themes by exporting them for backup or migration, and importing them across different projects. You can do this through the Descope Console or programmatically 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

Import and Initialize Management SDK

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

const managementKey = "xxxx"

try{
    //  baseUrl="<URL>" // When initializing the Descope client you can 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'
  }
)

Export Theme

Use the code below to export a theme:

import * as fs from 'fs';

// Args
//   None

const resp = await descopeClient.management.theme.export()
if (!resp.ok) {
  console.log(resp)
  console.log("Unable to export theme.")
  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 exported theme.")
  console.log(resp.data)
  let data = JSON.stringify(resp.data, null, 2);
  fs.writeFile('theme.json', data, (err) => {
      if (err) throw err;
      console.log('Theme written to file');
  });
}
import json

# Args
#   None
try:
  resp = descope_client.mgmt.flow.export_theme()
  print ("Successfully exported theme")
  print (resp)

  json_object = json.dumps(resp, indent=4)
  with open("theme.json", "w") as outfile:
    outfile.write(json_object)
except AuthException as error:
  print ("Failed to export theme")
  print ("Status Code: " + str(error.status_code))
  print ("Error: " + str(error.error_message))
import (
	"encoding/json"
	"errors"
	"fmt"
	"os"
	"strings"
)

// Args
//   None
res, err := descopeClient.Management.Flow().ExportTheme()
if err != nil {
  fmt.Print("Failed to export theme", err)
} else {
  data, err :=json.Marshal(res)
  if err == nil {
    fileName := fmt.Sprintf("theme.json")
    if err == nil {
      err = os.WriteFile(fileName, data, 0644)
      fmt.Println("Successfully exported flow")
    }
  }
}

Import Theme

Use the code below to import a theme:

import * as fs from 'fs';

// Args
// theme (Theme): the theme to import. dict in the format
//    {"id": "", "cssTemplate": {} }

let data = fs.readFileSync('theme.json');
let jsonData = JSON.parse(data);
const theme = jsonData["theme"]

const resp = await descopeClient.management.theme.import(theme)
if (!resp.ok) {
  console.log(resp)
  console.log("Unable to import theme.")
  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 imported theme.")
  console.log(resp.data)
}
import json

# Args
# theme (Theme): the theme to import. dict in the format
#    {"id": "", "cssTemplate": {} }

with open("theme.json", "r") as infile:
  themeJson = json.load(infile)
theme = themeJson["theme"]
try:
  resp = descope_client.mgmt.flow.import_theme(theme=theme)
  print ("Successfully imported theme")
  print (resp)
except AuthException as error:
  print ("Failed to import theme")
  print ("Status Code: " + str(error.status_code))
  print ("Error: " + str(error.error_message))
import (
	"encoding/json"
	"errors"
	"fmt"
	"os"
	"strings"
)

// Args
// theme (Theme): the theme to import. dict in the format
//    {"id": "", "cssTemplate": {} }
raw, err := os.ReadFile("theme.json")
if err != nil {
  return err
}
theme := &descope.Theme{}
err = json.Unmarshal(raw, theme)
if err != nil {
  return err
  }
res, err := descopeClient.Management.Flow().ImportTheme(theme)
if err != nil {
fmt.Print("Failed to import flow", err)
} else {
  fmt.Print("Successfully imported flow", res)
}
Was this helpful?

On this page