Create new OAuth client
curl --request POST \
--url https://{tenant}/tyk/oauth/clients/create \
--header 'Content-Type: application/json' \
--header 'X-Tyk-Authorization: <api-key>' \
--data '
{
"api_id": "b84fe1a04e5648927971c0557971565c",
"client_id": "2a06b398c17f46908de3dffcb71ef87df",
"description": "google client",
"meta_data": {
"user_id": "362b3fb9a1d5e4f00017226f5"
},
"redirect_uri": "https://httpbin.org/ip",
"secret": "MmQwNTI5NGQtYjU0YS00NjMyLWIwZjktNTZjY2M1ZjhjYWY0"
}
'import requests
url = "https://{tenant}/tyk/oauth/clients/create"
payload = {
"api_id": "b84fe1a04e5648927971c0557971565c",
"client_id": "2a06b398c17f46908de3dffcb71ef87df",
"description": "google client",
"meta_data": { "user_id": "362b3fb9a1d5e4f00017226f5" },
"redirect_uri": "https://httpbin.org/ip",
"secret": "MmQwNTI5NGQtYjU0YS00NjMyLWIwZjktNTZjY2M1ZjhjYWY0"
}
headers = {
"X-Tyk-Authorization": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'X-Tyk-Authorization': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
api_id: 'b84fe1a04e5648927971c0557971565c',
client_id: '2a06b398c17f46908de3dffcb71ef87df',
description: 'google client',
meta_data: {user_id: '362b3fb9a1d5e4f00017226f5'},
redirect_uri: 'https://httpbin.org/ip',
secret: 'MmQwNTI5NGQtYjU0YS00NjMyLWIwZjktNTZjY2M1ZjhjYWY0'
})
};
fetch('https://{tenant}/tyk/oauth/clients/create', 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}/tyk/oauth/clients/create",
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([
'api_id' => 'b84fe1a04e5648927971c0557971565c',
'client_id' => '2a06b398c17f46908de3dffcb71ef87df',
'description' => 'google client',
'meta_data' => [
'user_id' => '362b3fb9a1d5e4f00017226f5'
],
'redirect_uri' => 'https://httpbin.org/ip',
'secret' => 'MmQwNTI5NGQtYjU0YS00NjMyLWIwZjktNTZjY2M1ZjhjYWY0'
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"X-Tyk-Authorization: <api-key>"
],
]);
$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}/tyk/oauth/clients/create"
payload := strings.NewReader("{\n \"api_id\": \"b84fe1a04e5648927971c0557971565c\",\n \"client_id\": \"2a06b398c17f46908de3dffcb71ef87df\",\n \"description\": \"google client\",\n \"meta_data\": {\n \"user_id\": \"362b3fb9a1d5e4f00017226f5\"\n },\n \"redirect_uri\": \"https://httpbin.org/ip\",\n \"secret\": \"MmQwNTI5NGQtYjU0YS00NjMyLWIwZjktNTZjY2M1ZjhjYWY0\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("X-Tyk-Authorization", "<api-key>")
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}/tyk/oauth/clients/create")
.header("X-Tyk-Authorization", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"api_id\": \"b84fe1a04e5648927971c0557971565c\",\n \"client_id\": \"2a06b398c17f46908de3dffcb71ef87df\",\n \"description\": \"google client\",\n \"meta_data\": {\n \"user_id\": \"362b3fb9a1d5e4f00017226f5\"\n },\n \"redirect_uri\": \"https://httpbin.org/ip\",\n \"secret\": \"MmQwNTI5NGQtYjU0YS00NjMyLWIwZjktNTZjY2M1ZjhjYWY0\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://{tenant}/tyk/oauth/clients/create")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["X-Tyk-Authorization"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"api_id\": \"b84fe1a04e5648927971c0557971565c\",\n \"client_id\": \"2a06b398c17f46908de3dffcb71ef87df\",\n \"description\": \"google client\",\n \"meta_data\": {\n \"user_id\": \"362b3fb9a1d5e4f00017226f5\"\n },\n \"redirect_uri\": \"https://httpbin.org/ip\",\n \"secret\": \"MmQwNTI5NGQtYjU0YS00NjMyLWIwZjktNTZjY2M1ZjhjYWY0\"\n}"
response = http.request(request)
puts response.read_body{
"client_id": "2a06b398c17f46908de3dffcb71ef87df",
"description": "google client",
"meta_data": {
"user_id": "362b3fb9a1d5e4f00017226f5"
},
"redirect_uri": "https://httpbin.org/ip",
"secret": "MmQwNTI5NGQtYjU0YS00NjMyLWIwZjktNTZjY2M1ZjhjYWY0"
}{
"message": "API doesn't exist",
"status": "error"
}{
"message": "Attempted administrative access with invalid or missing key!",
"status": "error"
}{
"message": "Unmarshalling failed",
"status": "error"
}OAuth
Create new OAuth client
Any OAuth keys must be generated with the help of a client ID. These need to be pre-registered with Tyk before they can be used (in a similar vein to how you would register your app with Twitter before attempting to ask user permissions using their API).
Creating OAuth clients with Access to Multiple APIs
New from Tyk Gateway 2.6.0 is the ability to create OAuth clients with access to more than one API. If you provide the api_id it works the same as in previous releases. If you don’t provide the api_id the request uses policy access rights and enumerates APIs from their setting in the newly created OAuth-client.POST
/
tyk
/
oauth
/
clients
/
create
Create new OAuth client
curl --request POST \
--url https://{tenant}/tyk/oauth/clients/create \
--header 'Content-Type: application/json' \
--header 'X-Tyk-Authorization: <api-key>' \
--data '
{
"api_id": "b84fe1a04e5648927971c0557971565c",
"client_id": "2a06b398c17f46908de3dffcb71ef87df",
"description": "google client",
"meta_data": {
"user_id": "362b3fb9a1d5e4f00017226f5"
},
"redirect_uri": "https://httpbin.org/ip",
"secret": "MmQwNTI5NGQtYjU0YS00NjMyLWIwZjktNTZjY2M1ZjhjYWY0"
}
'import requests
url = "https://{tenant}/tyk/oauth/clients/create"
payload = {
"api_id": "b84fe1a04e5648927971c0557971565c",
"client_id": "2a06b398c17f46908de3dffcb71ef87df",
"description": "google client",
"meta_data": { "user_id": "362b3fb9a1d5e4f00017226f5" },
"redirect_uri": "https://httpbin.org/ip",
"secret": "MmQwNTI5NGQtYjU0YS00NjMyLWIwZjktNTZjY2M1ZjhjYWY0"
}
headers = {
"X-Tyk-Authorization": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'X-Tyk-Authorization': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
api_id: 'b84fe1a04e5648927971c0557971565c',
client_id: '2a06b398c17f46908de3dffcb71ef87df',
description: 'google client',
meta_data: {user_id: '362b3fb9a1d5e4f00017226f5'},
redirect_uri: 'https://httpbin.org/ip',
secret: 'MmQwNTI5NGQtYjU0YS00NjMyLWIwZjktNTZjY2M1ZjhjYWY0'
})
};
fetch('https://{tenant}/tyk/oauth/clients/create', 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}/tyk/oauth/clients/create",
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([
'api_id' => 'b84fe1a04e5648927971c0557971565c',
'client_id' => '2a06b398c17f46908de3dffcb71ef87df',
'description' => 'google client',
'meta_data' => [
'user_id' => '362b3fb9a1d5e4f00017226f5'
],
'redirect_uri' => 'https://httpbin.org/ip',
'secret' => 'MmQwNTI5NGQtYjU0YS00NjMyLWIwZjktNTZjY2M1ZjhjYWY0'
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"X-Tyk-Authorization: <api-key>"
],
]);
$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}/tyk/oauth/clients/create"
payload := strings.NewReader("{\n \"api_id\": \"b84fe1a04e5648927971c0557971565c\",\n \"client_id\": \"2a06b398c17f46908de3dffcb71ef87df\",\n \"description\": \"google client\",\n \"meta_data\": {\n \"user_id\": \"362b3fb9a1d5e4f00017226f5\"\n },\n \"redirect_uri\": \"https://httpbin.org/ip\",\n \"secret\": \"MmQwNTI5NGQtYjU0YS00NjMyLWIwZjktNTZjY2M1ZjhjYWY0\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("X-Tyk-Authorization", "<api-key>")
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}/tyk/oauth/clients/create")
.header("X-Tyk-Authorization", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"api_id\": \"b84fe1a04e5648927971c0557971565c\",\n \"client_id\": \"2a06b398c17f46908de3dffcb71ef87df\",\n \"description\": \"google client\",\n \"meta_data\": {\n \"user_id\": \"362b3fb9a1d5e4f00017226f5\"\n },\n \"redirect_uri\": \"https://httpbin.org/ip\",\n \"secret\": \"MmQwNTI5NGQtYjU0YS00NjMyLWIwZjktNTZjY2M1ZjhjYWY0\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://{tenant}/tyk/oauth/clients/create")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["X-Tyk-Authorization"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"api_id\": \"b84fe1a04e5648927971c0557971565c\",\n \"client_id\": \"2a06b398c17f46908de3dffcb71ef87df\",\n \"description\": \"google client\",\n \"meta_data\": {\n \"user_id\": \"362b3fb9a1d5e4f00017226f5\"\n },\n \"redirect_uri\": \"https://httpbin.org/ip\",\n \"secret\": \"MmQwNTI5NGQtYjU0YS00NjMyLWIwZjktNTZjY2M1ZjhjYWY0\"\n}"
response = http.request(request)
puts response.read_body{
"client_id": "2a06b398c17f46908de3dffcb71ef87df",
"description": "google client",
"meta_data": {
"user_id": "362b3fb9a1d5e4f00017226f5"
},
"redirect_uri": "https://httpbin.org/ip",
"secret": "MmQwNTI5NGQtYjU0YS00NjMyLWIwZjktNTZjY2M1ZjhjYWY0"
}{
"message": "API doesn't exist",
"status": "error"
}{
"message": "Attempted administrative access with invalid or missing key!",
"status": "error"
}{
"message": "Unmarshalling failed",
"status": "error"
}Authorizations
Api key
Body
application/json
Example:
"keyless"
Example:
"2a06b398c17f46908de3dffcb71ef87b"
Example:
"google client login"
Show child attributes
Show child attributes
Example:
"https://httpbin.org/ip"
Example:
"MmQwNTI5NGQtYjU0YS00NjMyLWIwZjktNTZjY2M1ZjhjYWY0"
Response
Client created
Example:
"keyless"
Example:
"2a06b398c17f46908de3dffcb71ef87b"
Example:
"google client login"
Show child attributes
Show child attributes
Example:
"https://httpbin.org/ip"
Example:
"MmQwNTI5NGQtYjU0YS00NjMyLWIwZjktNTZjY2M1ZjhjYWY0"
Was this page helpful?
Get API IDs for APIS that use the specified client_id(appID) for OAuth
Previous
Invalidate OAuth refresh token
Next
⌘I