Appliance Administration: Automatic Creation of Tenants

If your business needs require you to create tenants regularly, you may automate this process in your Appliance instances. For example, you might need to create one tenant for each customer or project that goes live.

Creating a Management API Client for the Root Tenant Authority

  1. Choose the Root Tenant Authority (RTA) tenant using the drop-down menu located in the top right-hand side of the Dashboard.
  2. Go to the Applications page.
  3. Create an application called 'Tenant Provisioning.'
  4. Once you have created the 'Tenant Provisioning' client, go to the Connections tab and disable all Connections for this client.
  5. Navigate to https://manage.auth0.com/#/apis. Click the link to open the Auth0 Management API.
  6. Go to the Non Interactive Clients tab, and enable Tenant Provisioning by moving the associated slide to the right.
  7. Create the new client grant.

Creating the New Client Grant

  1. Navigate to the Management API Explorer to generate the required POST call.

  2. Click the bubble that says 'create:client_grants' to select that Scope.

  3. Paste the following payload into the provided body box after you have supplied the client ID and the root tenant authority:

    {
     'client_id': '{CLIENT_ID}',
     'audience': 'https://{RTA}/api/v2/',
     'scope': ['create:tenants']
    }
    
  4. Click 'Try' to test the provided information. If you receive a 201 response, you may proceed to click on the 'get curl command' link to generate the required POST call. It will contain the following information:

    
    
    curl --request POST \
      --url https://%7BRTA_DOMAIN%7D/api/v2/client-grants \
      --data '{ "client_id": "{CLIENT_ID}", "audience": "https://{RTA}/api/v2/", "scope": ["create:tenants"] }'
    var client = new RestClient("https://%7BRTA_DOMAIN%7D/api/v2/client-grants");
    var request = new RestRequest(Method.POST);
    request.AddParameter("undefined", "{ \"client_id\": \"{CLIENT_ID}\", \"audience\": \"https://{RTA}/api/v2/\", \"scope\": [\"create:tenants\"] }", ParameterType.RequestBody);
    IRestResponse response = client.Execute(request);
    package main
    
    import (
    	"fmt"
    	"strings"
    	"net/http"
    	"io/ioutil"
    )
    
    func main() {
    
    	url := "https://%7BRTA_DOMAIN%7D/api/v2/client-grants"
    
    	payload := strings.NewReader("{ \"client_id\": \"{CLIENT_ID}\", \"audience\": \"https://{RTA}/api/v2/\", \"scope\": [\"create:tenants\"] }")
    
    	req, _ := http.NewRequest("POST", url, payload)
    
    	res, _ := http.DefaultClient.Do(req)
    
    	defer res.Body.Close()
    	body, _ := ioutil.ReadAll(res.Body)
    
    	fmt.Println(res)
    	fmt.Println(string(body))
    
    }
    HttpResponse<String> response = Unirest.post("https://%7BRTA_DOMAIN%7D/api/v2/client-grants")
      .body("{ \"client_id\": \"{CLIENT_ID}\", \"audience\": \"https://{RTA}/api/v2/\", \"scope\": [\"create:tenants\"] }")
      .asString();
    var settings = {
      "async": true,
      "crossDomain": true,
      "url": "https://%7BRTA_DOMAIN%7D/api/v2/client-grants",
      "method": "POST",
      "headers": {},
      "processData": false,
      "data": "{ \"client_id\": \"{CLIENT_ID}\", \"audience\": \"https://{RTA}/api/v2/\", \"scope\": [\"create:tenants\"] }"
    }
    
    $.ajax(settings).done(function (response) {
      console.log(response);
    });
    var request = require("request");
    
    var options = { method: 'POST',
      url: 'https://%7BRTA_DOMAIN%7D/api/v2/client-grants',
      body: 
       { client_id: '{CLIENT_ID}',
         audience: 'https://{RTA}/api/v2/',
         scope: [ 'create:tenants' ] },
      json: true };
    
    request(options, function (error, response, body) {
      if (error) throw new Error(error);
    
      console.log(body);
    });
    
    #import <Foundation/Foundation.h>
    NSDictionary *parameters = @{ @"client_id": @"{CLIENT_ID}",
                                  @"audience": @"https://{RTA}/api/v2/",
                                  @"scope": @[ @"create:tenants" ] };
    
    NSData *postData = [NSJSONSerialization dataWithJSONObject:parameters options:0 error:nil];
    
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"https://%7BRTA_DOMAIN%7D/api/v2/client-grants"]
                                                           cachePolicy:NSURLRequestUseProtocolCachePolicy
                                                       timeoutInterval:10.0];
    [request setHTTPMethod:@"POST"];
    [request setHTTPBody:postData];
    
    NSURLSession *session = [NSURLSession sharedSession];
    NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request
                                                completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
                                                    if (error) {
                                                        NSLog(@"%@", error);
                                                    } else {
                                                        NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *) response;
                                                        NSLog(@"%@", httpResponse);
                                                    }
                                                }];
    [dataTask resume];
    $curl = curl_init();
    
    curl_setopt_array($curl, array(
      CURLOPT_URL => "https://%7BRTA_DOMAIN%7D/api/v2/client-grants",
      CURLOPT_RETURNTRANSFER => true,
      CURLOPT_ENCODING => "",
      CURLOPT_MAXREDIRS => 10,
      CURLOPT_TIMEOUT => 30,
      CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
      CURLOPT_CUSTOMREQUEST => "POST",
      CURLOPT_POSTFIELDS => "{ \"client_id\": \"{CLIENT_ID}\", \"audience\": \"https://{RTA}/api/v2/\", \"scope\": [\"create:tenants\"] }",
    ));
    
    $response = curl_exec($curl);
    $err = curl_error($curl);
    
    curl_close($curl);
    
    if ($err) {
      echo "cURL Error #:" . $err;
    } else {
      echo $response;
    }
    import http.client
    
    conn = http.client.HTTPSConnection("")
    
    payload = "{ \"client_id\": \"{CLIENT_ID}\", \"audience\": \"https://{RTA}/api/v2/\", \"scope\": [\"create:tenants\"] }"
    
    conn.request("POST", "%7BRTA_DOMAIN%7D/api/v2/client-grants", payload)
    
    res = conn.getresponse()
    data = res.read()
    
    print(data.decode("utf-8"))
    require 'uri'
    require 'net/http'
    
    url = URI("https://%7BRTA_DOMAIN%7D/api/v2/client-grants")
    
    http = Net::HTTP.new(url.host, url.port)
    http.use_ssl = true
    http.verify_mode = OpenSSL::SSL::VERIFY_NONE
    
    request = Net::HTTP::Post.new(url)
    request.body = "{ \"client_id\": \"{CLIENT_ID}\", \"audience\": \"https://{RTA}/api/v2/\", \"scope\": [\"create:tenants\"] }"
    
    response = http.request(request)
    puts response.read_body
    import Foundation
    let parameters = [
      "client_id": "{CLIENT_ID}",
      "audience": "https://{RTA}/api/v2/",
      "scope": ["create:tenants"]
    ]
    
    let postData = NSJSONSerialization.dataWithJSONObject(parameters, options: nil, error: nil)
    
    var request = NSMutableURLRequest(URL: NSURL(string: "https://%7BRTA_DOMAIN%7D/api/v2/client-grants")!,
                                            cachePolicy: .UseProtocolCachePolicy,
                                        timeoutInterval: 10.0)
    request.HTTPMethod = "POST"
    request.HTTPBody = postData
    
    let session = NSURLSession.sharedSession()
    let dataTask = session.dataTaskWithRequest(request, completionHandler: { (data, response, error) -> Void in
      if (error != nil) {
        println(error)
      } else {
        let httpResponse = response as? NSHTTPURLResponse
        println(httpResponse)
      }
    })
    
    dataTask.resume()

Using the New Client grant

Once you have created your New Client Grant, you may use it to complete the following tasks.

Getting an Access Token


curl --request POST \
  --url https://%7BRTA_DOMAIN%7D/oauth/token \
  --header 'cache-control: no-cache' \
  --header 'content-type: application/json' \
  --data '{"audience": "https://{RTA}/api/v2/", "grant_type": "client_credentials","client_id": "{CLIENT_ID}", "client_secret": "{CLIENT_SECRET}"}'
var client = new RestClient("https://%7BRTA_DOMAIN%7D/oauth/token");
var request = new RestRequest(Method.POST);
request.AddHeader("content-type", "application/json");
request.AddHeader("cache-control", "no-cache");
request.AddParameter("application/json", "{\"audience\": \"https://{RTA}/api/v2/\", \"grant_type\": \"client_credentials\",\"client_id\": \"{CLIENT_ID}\", \"client_secret\": \"{CLIENT_SECRET}\"}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io/ioutil"
)

func main() {

	url := "https://%7BRTA_DOMAIN%7D/oauth/token"

	payload := strings.NewReader("{\"audience\": \"https://{RTA}/api/v2/\", \"grant_type\": \"client_credentials\",\"client_id\": \"{CLIENT_ID}\", \"client_secret\": \"{CLIENT_SECRET}\"}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("cache-control", "no-cache")
	req.Header.Add("content-type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := ioutil.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
HttpResponse<String> response = Unirest.post("https://%7BRTA_DOMAIN%7D/oauth/token")
  .header("cache-control", "no-cache")
  .header("content-type", "application/json")
  .body("{\"audience\": \"https://{RTA}/api/v2/\", \"grant_type\": \"client_credentials\",\"client_id\": \"{CLIENT_ID}\", \"client_secret\": \"{CLIENT_SECRET}\"}")
  .asString();
var settings = {
  "async": true,
  "crossDomain": true,
  "url": "https://%7BRTA_DOMAIN%7D/oauth/token",
  "method": "POST",
  "headers": {
    "cache-control": "no-cache",
    "content-type": "application/json"
  },
  "processData": false,
  "data": "{\"audience\": \"https://{RTA}/api/v2/\", \"grant_type\": \"client_credentials\",\"client_id\": \"{CLIENT_ID}\", \"client_secret\": \"{CLIENT_SECRET}\"}"
}

$.ajax(settings).done(function (response) {
  console.log(response);
});
var request = require("request");

var options = { method: 'POST',
  url: 'https://%7BRTA_DOMAIN%7D/oauth/token',
  headers: 
   { 'content-type': 'application/json',
     'cache-control': 'no-cache' },
  body: 
   { audience: 'https://{RTA}/api/v2/',
     grant_type: 'client_credentials',
     client_id: '{CLIENT_ID}',
     client_secret: '{CLIENT_SECRET}' },
  json: true };

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});
#import <Foundation/Foundation.h>

NSDictionary *headers = @{ @"cache-control": @"no-cache",
                           @"content-type": @"application/json" };
NSDictionary *parameters = @{ @"audience": @"https://{RTA}/api/v2/",
                              @"grant_type": @"client_credentials",
                              @"client_id": @"{CLIENT_ID}",
                              @"client_secret": @"{CLIENT_SECRET}" };

NSData *postData = [NSJSONSerialization dataWithJSONObject:parameters options:0 error:nil];

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"https://%7BRTA_DOMAIN%7D/oauth/token"]
                                                       cachePolicy:NSURLRequestUseProtocolCachePolicy
                                                   timeoutInterval:10.0];
[request setHTTPMethod:@"POST"];
[request setAllHTTPHeaderFields:headers];
[request setHTTPBody:postData];

NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request
                                            completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
                                                if (error) {
                                                    NSLog(@"%@", error);
                                                } else {
                                                    NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *) response;
                                                    NSLog(@"%@", httpResponse);
                                                }
                                            }];
[dataTask resume];
$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://%7BRTA_DOMAIN%7D/oauth/token",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => "{\"audience\": \"https://{RTA}/api/v2/\", \"grant_type\": \"client_credentials\",\"client_id\": \"{CLIENT_ID}\", \"client_secret\": \"{CLIENT_SECRET}\"}",
  CURLOPT_HTTPHEADER => array(
    "cache-control: no-cache",
    "content-type: application/json"
  ),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}
import http.client

conn = http.client.HTTPSConnection("")

payload = "{\"audience\": \"https://{RTA}/api/v2/\", \"grant_type\": \"client_credentials\",\"client_id\": \"{CLIENT_ID}\", \"client_secret\": \"{CLIENT_SECRET}\"}"

headers = {
    'cache-control': "no-cache",
    'content-type': "application/json"
    }

conn.request("POST", "%7BRTA_DOMAIN%7D/oauth/token", payload, headers)

res = conn.getresponse()
data = res.read()

print(data.decode("utf-8"))
require 'uri'
require 'net/http'

url = URI("https://%7BRTA_DOMAIN%7D/oauth/token")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE

request = Net::HTTP::Post.new(url)
request["cache-control"] = 'no-cache'
request["content-type"] = 'application/json'
request.body = "{\"audience\": \"https://{RTA}/api/v2/\", \"grant_type\": \"client_credentials\",\"client_id\": \"{CLIENT_ID}\", \"client_secret\": \"{CLIENT_SECRET}\"}"

response = http.request(request)
puts response.read_body
import Foundation

let headers = [
  "cache-control": "no-cache",
  "content-type": "application/json"
]
let parameters = [
  "audience": "https://{RTA}/api/v2/",
  "grant_type": "client_credentials",
  "client_id": "{CLIENT_ID}",
  "client_secret": "{CLIENT_SECRET}"
]

let postData = NSJSONSerialization.dataWithJSONObject(parameters, options: nil, error: nil)

var request = NSMutableURLRequest(URL: NSURL(string: "https://%7BRTA_DOMAIN%7D/oauth/token")!,
                                        cachePolicy: .UseProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.HTTPMethod = "POST"
request.allHTTPHeaderFields = headers
request.HTTPBody = postData

let session = NSURLSession.sharedSession()
let dataTask = session.dataTaskWithRequest(request, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    println(error)
  } else {
    let httpResponse = response as? NSHTTPURLResponse
    println(httpResponse)
  }
})

dataTask.resume()

In return, you will receive the Access token:

{
   'access_token': 'eyJ0eXAiO...'
}

Creating a Tenant

You may use the following call create a tenant. Once the tenant is created, the API responds with a Client ID and Secret that grants access to the Management API for the newly-created tenant (which you can then use to get additional access tokens--see the following section for the sample call).


curl --request POST \
  --url https://%7BRTA_DOMAIN%7D/api/v2/tenants \
  --header 'authorization: Bearer {ACCESS_TOKEN}' \
  --header 'cache-control: no-cache' \
  --header 'content-type: application/json' \
  --data '{"name": "customer-1","owners": ["me@email.com"]}'
var client = new RestClient("https://%7BRTA_DOMAIN%7D/api/v2/tenants");
var request = new RestRequest(Method.POST);
request.AddHeader("authorization", "Bearer {ACCESS_TOKEN}");
request.AddHeader("content-type", "application/json");
request.AddHeader("cache-control", "no-cache");
request.AddParameter("application/json", "{\"name\": \"customer-1\",\"owners\": [\"me@email.com\"]}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io/ioutil"
)

func main() {

	url := "https://%7BRTA_DOMAIN%7D/api/v2/tenants"

	payload := strings.NewReader("{\"name\": \"customer-1\",\"owners\": [\"me@email.com\"]}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("cache-control", "no-cache")
	req.Header.Add("content-type", "application/json")
	req.Header.Add("authorization", "Bearer {ACCESS_TOKEN}")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := ioutil.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
HttpResponse<String> response = Unirest.post("https://%7BRTA_DOMAIN%7D/api/v2/tenants")
  .header("cache-control", "no-cache")
  .header("content-type", "application/json")
  .header("authorization", "Bearer {ACCESS_TOKEN}")
  .body("{\"name\": \"customer-1\",\"owners\": [\"me@email.com\"]}")
  .asString();
var settings = {
  "async": true,
  "crossDomain": true,
  "url": "https://%7BRTA_DOMAIN%7D/api/v2/tenants",
  "method": "POST",
  "headers": {
    "cache-control": "no-cache",
    "content-type": "application/json",
    "authorization": "Bearer {ACCESS_TOKEN}"
  },
  "processData": false,
  "data": "{\"name\": \"customer-1\",\"owners\": [\"me@email.com\"]}"
}

$.ajax(settings).done(function (response) {
  console.log(response);
});
var request = require("request");

var options = { method: 'POST',
  url: 'https://%7BRTA_DOMAIN%7D/api/v2/tenants',
  headers: 
   { authorization: 'Bearer {ACCESS_TOKEN}',
     'content-type': 'application/json',
     'cache-control': 'no-cache' },
  body: { name: 'customer-1', owners: [ 'me@email.com' ] },
  json: true };

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});
#import <Foundation/Foundation.h>

NSDictionary *headers = @{ @"cache-control": @"no-cache",
                           @"content-type": @"application/json",
                           @"authorization": @"Bearer {ACCESS_TOKEN}" };
NSDictionary *parameters = @{ @"name": @"customer-1",
                              @"owners": @[ @"me@email.com" ] };

NSData *postData = [NSJSONSerialization dataWithJSONObject:parameters options:0 error:nil];

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"https://%7BRTA_DOMAIN%7D/api/v2/tenants"]
                                                       cachePolicy:NSURLRequestUseProtocolCachePolicy
                                                   timeoutInterval:10.0];
[request setHTTPMethod:@"POST"];
[request setAllHTTPHeaderFields:headers];
[request setHTTPBody:postData];

NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request
                                            completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
                                                if (error) {
                                                    NSLog(@"%@", error);
                                                } else {
                                                    NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *) response;
                                                    NSLog(@"%@", httpResponse);
                                                }
                                            }];
[dataTask resume];
$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://%7BRTA_DOMAIN%7D/api/v2/tenants",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => "{\"name\": \"customer-1\",\"owners\": [\"me@email.com\"]}",
  CURLOPT_HTTPHEADER => array(
    "authorization: Bearer {ACCESS_TOKEN}",
    "cache-control: no-cache",
    "content-type: application/json"
  ),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}
import http.client

conn = http.client.HTTPSConnection("")

payload = "{\"name\": \"customer-1\",\"owners\": [\"me@email.com\"]}"

headers = {
    'cache-control': "no-cache",
    'content-type': "application/json",
    'authorization': "Bearer {ACCESS_TOKEN}"
    }

conn.request("POST", "%7BRTA_DOMAIN%7D/api/v2/tenants", payload, headers)

res = conn.getresponse()
data = res.read()

print(data.decode("utf-8"))
require 'uri'
require 'net/http'

url = URI("https://%7BRTA_DOMAIN%7D/api/v2/tenants")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE

request = Net::HTTP::Post.new(url)
request["cache-control"] = 'no-cache'
request["content-type"] = 'application/json'
request["authorization"] = 'Bearer {ACCESS_TOKEN}'
request.body = "{\"name\": \"customer-1\",\"owners\": [\"me@email.com\"]}"

response = http.request(request)
puts response.read_body
import Foundation

let headers = [
  "cache-control": "no-cache",
  "content-type": "application/json",
  "authorization": "Bearer {ACCESS_TOKEN}"
]
let parameters = [
  "name": "customer-1",
  "owners": ["me@email.com"]
]

let postData = NSJSONSerialization.dataWithJSONObject(parameters, options: nil, error: nil)

var request = NSMutableURLRequest(URL: NSURL(string: "https://%7BRTA_DOMAIN%7D/api/v2/tenants")!,
                                        cachePolicy: .UseProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.HTTPMethod = "POST"
request.allHTTPHeaderFields = headers
request.HTTPBody = postData

let session = NSURLSession.sharedSession()
let dataTask = session.dataTaskWithRequest(request, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    println(error)
  } else {
    let httpResponse = response as? NSHTTPURLResponse
    println(httpResponse)
  }
})

dataTask.resume()

Getting an Access Token for the Newly-Created Tenant

This snippet shows how you can get an access token for the newly-created tenant, which you can then use to call the Management API.


curl --request POST \
  --url https://%7BNEW_TENANT_DOMAIN%7D/oauth/token \
  --header 'cache-control: no-cache' \
  --header 'content-type: application/json' \
  --data '{"audience": "https://{NEW_TENANT_DOMAIN}/api/v2/", "grant_type": "client_credentials", "client_id": "{MANAGEMENT_CLIENT_ID}", "client_secret": "{MANAGEMENT_CLIENT_SECRET}"}'
var client = new RestClient("https://%7BNEW_TENANT_DOMAIN%7D/oauth/token");
var request = new RestRequest(Method.POST);
request.AddHeader("content-type", "application/json");
request.AddHeader("cache-control", "no-cache");
request.AddParameter("application/json", "{\"audience\": \"https://{NEW_TENANT_DOMAIN}/api/v2/\", \"grant_type\": \"client_credentials\", \"client_id\": \"{MANAGEMENT_CLIENT_ID}\", \"client_secret\": \"{MANAGEMENT_CLIENT_SECRET}\"}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io/ioutil"
)

func main() {

	url := "https://%7BNEW_TENANT_DOMAIN%7D/oauth/token"

	payload := strings.NewReader("{\"audience\": \"https://{NEW_TENANT_DOMAIN}/api/v2/\", \"grant_type\": \"client_credentials\", \"client_id\": \"{MANAGEMENT_CLIENT_ID}\", \"client_secret\": \"{MANAGEMENT_CLIENT_SECRET}\"}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("cache-control", "no-cache")
	req.Header.Add("content-type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := ioutil.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
HttpResponse<String> response = Unirest.post("https://%7BNEW_TENANT_DOMAIN%7D/oauth/token")
  .header("cache-control", "no-cache")
  .header("content-type", "application/json")
  .body("{\"audience\": \"https://{NEW_TENANT_DOMAIN}/api/v2/\", \"grant_type\": \"client_credentials\", \"client_id\": \"{MANAGEMENT_CLIENT_ID}\", \"client_secret\": \"{MANAGEMENT_CLIENT_SECRET}\"}")
  .asString();
var settings = {
  "async": true,
  "crossDomain": true,
  "url": "https://%7BNEW_TENANT_DOMAIN%7D/oauth/token",
  "method": "POST",
  "headers": {
    "cache-control": "no-cache",
    "content-type": "application/json"
  },
  "processData": false,
  "data": "{\"audience\": \"https://{NEW_TENANT_DOMAIN}/api/v2/\", \"grant_type\": \"client_credentials\", \"client_id\": \"{MANAGEMENT_CLIENT_ID}\", \"client_secret\": \"{MANAGEMENT_CLIENT_SECRET}\"}"
}

$.ajax(settings).done(function (response) {
  console.log(response);
});
var request = require("request");

var options = { method: 'POST',
  url: 'https://%7BNEW_TENANT_DOMAIN%7D/oauth/token',
  headers: 
   { 'content-type': 'application/json',
     'cache-control': 'no-cache' },
  body: 
   { audience: 'https://{NEW_TENANT_DOMAIN}/api/v2/',
     grant_type: 'client_credentials',
     client_id: '{MANAGEMENT_CLIENT_ID}',
     client_secret: '{MANAGEMENT_CLIENT_SECRET}' },
  json: true };

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});
#import <Foundation/Foundation.h>

NSDictionary *headers = @{ @"cache-control": @"no-cache",
                           @"content-type": @"application/json" };
NSDictionary *parameters = @{ @"audience": @"https://{NEW_TENANT_DOMAIN}/api/v2/",
                              @"grant_type": @"client_credentials",
                              @"client_id": @"{MANAGEMENT_CLIENT_ID}",
                              @"client_secret": @"{MANAGEMENT_CLIENT_SECRET}" };

NSData *postData = [NSJSONSerialization dataWithJSONObject:parameters options:0 error:nil];

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"https://%7BNEW_TENANT_DOMAIN%7D/oauth/token"]
                                                       cachePolicy:NSURLRequestUseProtocolCachePolicy
                                                   timeoutInterval:10.0];
[request setHTTPMethod:@"POST"];
[request setAllHTTPHeaderFields:headers];
[request setHTTPBody:postData];

NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request
                                            completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
                                                if (error) {
                                                    NSLog(@"%@", error);
                                                } else {
                                                    NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *) response;
                                                    NSLog(@"%@", httpResponse);
                                                }
                                            }];
[dataTask resume];
$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://%7BNEW_TENANT_DOMAIN%7D/oauth/token",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => "{\"audience\": \"https://{NEW_TENANT_DOMAIN}/api/v2/\", \"grant_type\": \"client_credentials\", \"client_id\": \"{MANAGEMENT_CLIENT_ID}\", \"client_secret\": \"{MANAGEMENT_CLIENT_SECRET}\"}",
  CURLOPT_HTTPHEADER => array(
    "cache-control: no-cache",
    "content-type: application/json"
  ),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}
import http.client

conn = http.client.HTTPSConnection("")

payload = "{\"audience\": \"https://{NEW_TENANT_DOMAIN}/api/v2/\", \"grant_type\": \"client_credentials\", \"client_id\": \"{MANAGEMENT_CLIENT_ID}\", \"client_secret\": \"{MANAGEMENT_CLIENT_SECRET}\"}"

headers = {
    'cache-control': "no-cache",
    'content-type': "application/json"
    }

conn.request("POST", "%7BNEW_TENANT_DOMAIN%7D/oauth/token", payload, headers)

res = conn.getresponse()
data = res.read()

print(data.decode("utf-8"))
require 'uri'
require 'net/http'

url = URI("https://%7BNEW_TENANT_DOMAIN%7D/oauth/token")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE

request = Net::HTTP::Post.new(url)
request["cache-control"] = 'no-cache'
request["content-type"] = 'application/json'
request.body = "{\"audience\": \"https://{NEW_TENANT_DOMAIN}/api/v2/\", \"grant_type\": \"client_credentials\", \"client_id\": \"{MANAGEMENT_CLIENT_ID}\", \"client_secret\": \"{MANAGEMENT_CLIENT_SECRET}\"}"

response = http.request(request)
puts response.read_body
import Foundation

let headers = [
  "cache-control": "no-cache",
  "content-type": "application/json"
]
let parameters = [
  "audience": "https://{NEW_TENANT_DOMAIN}/api/v2/",
  "grant_type": "client_credentials",
  "client_id": "{MANAGEMENT_CLIENT_ID}",
  "client_secret": "{MANAGEMENT_CLIENT_SECRET}"
]

let postData = NSJSONSerialization.dataWithJSONObject(parameters, options: nil, error: nil)

var request = NSMutableURLRequest(URL: NSURL(string: "https://%7BNEW_TENANT_DOMAIN%7D/oauth/token")!,
                                        cachePolicy: .UseProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.HTTPMethod = "POST"
request.allHTTPHeaderFields = headers
request.HTTPBody = postData

let session = NSURLSession.sharedSession()
let dataTask = session.dataTaskWithRequest(request, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    println(error)
  } else {
    let httpResponse = response as? NSHTTPURLResponse
    println(httpResponse)
  }
})

dataTask.resume()