Create a new OAuth2.0 client.
curl --request POST \
--url https://{tenant}/api/apis/oauth/{apiId} \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"meta_data": {
"user_id": "362b3fb9a1d5e4f00017226f5"
},
"policy_id": "665d51505715ec2d76022c87",
"redirect_uri": "https://httpbin.org/ip"
}
'import requests
url = "https://{tenant}/api/apis/oauth/{apiId}"
payload = {
"meta_data": { "user_id": "362b3fb9a1d5e4f00017226f5" },
"policy_id": "665d51505715ec2d76022c87",
"redirect_uri": "https://httpbin.org/ip"
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
meta_data: {user_id: '362b3fb9a1d5e4f00017226f5'},
policy_id: '665d51505715ec2d76022c87',
redirect_uri: 'https://httpbin.org/ip'
})
};
fetch('https://{tenant}/api/apis/oauth/{apiId}', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://{tenant}/api/apis/oauth/{apiId}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'meta_data' => [
'user_id' => '362b3fb9a1d5e4f00017226f5'
],
'policy_id' => '665d51505715ec2d76022c87',
'redirect_uri' => 'https://httpbin.org/ip'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://{tenant}/api/apis/oauth/{apiId}"
payload := strings.NewReader("{\n \"meta_data\": {\n \"user_id\": \"362b3fb9a1d5e4f00017226f5\"\n },\n \"policy_id\": \"665d51505715ec2d76022c87\",\n \"redirect_uri\": \"https://httpbin.org/ip\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://{tenant}/api/apis/oauth/{apiId}")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"meta_data\": {\n \"user_id\": \"362b3fb9a1d5e4f00017226f5\"\n },\n \"policy_id\": \"665d51505715ec2d76022c87\",\n \"redirect_uri\": \"https://httpbin.org/ip\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://{tenant}/api/apis/oauth/{apiId}")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"meta_data\": {\n \"user_id\": \"362b3fb9a1d5e4f00017226f5\"\n },\n \"policy_id\": \"665d51505715ec2d76022c87\",\n \"redirect_uri\": \"https://httpbin.org/ip\"\n}"
response = http.request(request)
puts response.read_body{
"client_id": "2a06b398c17f46908de3dffcb71ef87d",
"client_name": "",
"dcr_registration": {
"access_token": "",
"client_uri": "",
"provider": ""
},
"description": "google client",
"meta_data": {
"user_id": "362b3fb9a1d5e4f00017226f5"
},
"policy_id": "665d51505715ec2d76022c87",
"redirect_uri": "https://httpbin.org/ip",
"secret": "MmQwNTI5NGQtYjU0YS00NjMyLWIwZjktNTZjY2M1ZjhjYWY0"
}{
"Message": "API reference not found.",
"Meta": null,
"Status": "Error"
}{
"Message": "Not authorised",
"Meta": null,
"Status": "Error"
}{
"Message": "Request body malformed.",
"Meta": null,
"Status": "Error"
}{
"Message": "Could not retrieve policy details.",
"Meta": null,
"Status": "Error"
}Oauth
Create a new OAuth2.0 client.
Client apps are created dynamically, the only parameter required to create a new client app with Tyk is to specify the redirect URI, this is used as part of the client authentication and cannot be edited later. Please note that if you don’t attach a policy to the OAuth client you will need to provide dynamic key rules to client authorization endpoint.
POST
/
api
/
apis
/
oauth
/
{apiId}
Create a new OAuth2.0 client.
curl --request POST \
--url https://{tenant}/api/apis/oauth/{apiId} \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"meta_data": {
"user_id": "362b3fb9a1d5e4f00017226f5"
},
"policy_id": "665d51505715ec2d76022c87",
"redirect_uri": "https://httpbin.org/ip"
}
'import requests
url = "https://{tenant}/api/apis/oauth/{apiId}"
payload = {
"meta_data": { "user_id": "362b3fb9a1d5e4f00017226f5" },
"policy_id": "665d51505715ec2d76022c87",
"redirect_uri": "https://httpbin.org/ip"
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
meta_data: {user_id: '362b3fb9a1d5e4f00017226f5'},
policy_id: '665d51505715ec2d76022c87',
redirect_uri: 'https://httpbin.org/ip'
})
};
fetch('https://{tenant}/api/apis/oauth/{apiId}', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://{tenant}/api/apis/oauth/{apiId}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'meta_data' => [
'user_id' => '362b3fb9a1d5e4f00017226f5'
],
'policy_id' => '665d51505715ec2d76022c87',
'redirect_uri' => 'https://httpbin.org/ip'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://{tenant}/api/apis/oauth/{apiId}"
payload := strings.NewReader("{\n \"meta_data\": {\n \"user_id\": \"362b3fb9a1d5e4f00017226f5\"\n },\n \"policy_id\": \"665d51505715ec2d76022c87\",\n \"redirect_uri\": \"https://httpbin.org/ip\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://{tenant}/api/apis/oauth/{apiId}")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"meta_data\": {\n \"user_id\": \"362b3fb9a1d5e4f00017226f5\"\n },\n \"policy_id\": \"665d51505715ec2d76022c87\",\n \"redirect_uri\": \"https://httpbin.org/ip\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://{tenant}/api/apis/oauth/{apiId}")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"meta_data\": {\n \"user_id\": \"362b3fb9a1d5e4f00017226f5\"\n },\n \"policy_id\": \"665d51505715ec2d76022c87\",\n \"redirect_uri\": \"https://httpbin.org/ip\"\n}"
response = http.request(request)
puts response.read_body{
"client_id": "2a06b398c17f46908de3dffcb71ef87d",
"client_name": "",
"dcr_registration": {
"access_token": "",
"client_uri": "",
"provider": ""
},
"description": "google client",
"meta_data": {
"user_id": "362b3fb9a1d5e4f00017226f5"
},
"policy_id": "665d51505715ec2d76022c87",
"redirect_uri": "https://httpbin.org/ip",
"secret": "MmQwNTI5NGQtYjU0YS00NjMyLWIwZjktNTZjY2M1ZjhjYWY0"
}{
"Message": "API reference not found.",
"Meta": null,
"Status": "Error"
}{
"Message": "Not authorised",
"Meta": null,
"Status": "Error"
}{
"Message": "Request body malformed.",
"Meta": null,
"Status": "Error"
}{
"Message": "Could not retrieve policy details.",
"Meta": null,
"Status": "Error"
}Authorizations
The Tyk Dashboard API Access Credentials
Path Parameters
The API’s ID.
Body
application/json
Was this page helpful?
⌘I