Passer au contenu principal
POST
https://{tenantDomain}/api/v2
/
client-grants
Go
package example

import (
    context "context"

    management "github.com/auth0/go-auth0/management/management"
    client "github.com/auth0/go-auth0/management/management/client"
    option "github.com/auth0/go-auth0/management/management/option"
)

func do() {
    client := client.NewClient(
        option.WithToken(
            "<token>",
        ),
    )
    request := &management.CreateClientGrantRequestContent{
        ClientId: "client_id",
        Audience: "audience",
        Scope: []string{
            "scope",
        },
    }
    client.ClientGrants.Create(
        context.TODO(),
        request,
    )
}
import { ManagementClient } from "auth0";

async function main() {
    const client = new ManagementClient({
        token: "<token>",
    });
    await client.clientGrants.create({
        clientId: "client_id",
        audience: "audience",
        scope: [
            "scope",
        ],
    });
}
main();
import { ManagementClient } from "auth0";

async function main() {
    const client = new ManagementClient({
        token: "<token>",
    });
    await client.clientGrants.create({
        clientId: "client_id",
        audience: "audience",
        scope: [
            "scope",
        ],
    });
}
main();
curl --request POST \
  --url https://{tenantDomain}/api/v2/client-grants \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '
{
  "audience": "<string>",
  "client_id": "<string>",
  "default_for": "third_party_clients",
  "allow_any_organization": false,
  "scope": [
    "<string>"
  ],
  "authorization_details_types": [
    "<string>"
  ],
  "allow_all_scopes": true
}
'
import requests

url = "https://{tenantDomain}/api/v2/client-grants"

payload = {
    "audience": "<string>",
    "client_id": "<string>",
    "default_for": "third_party_clients",
    "allow_any_organization": False,
    "scope": ["<string>"],
    "authorization_details_types": ["<string>"],
    "allow_all_scopes": True
}
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.text)
<?php

$curl = curl_init();

curl_setopt_array($curl, [
  CURLOPT_URL => "https://{tenantDomain}/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 => json_encode([
    'audience' => '<string>',
    'client_id' => '<string>',
    'default_for' => 'third_party_clients',
    'allow_any_organization' => false,
    'scope' => [
        '<string>'
    ],
    'authorization_details_types' => [
        '<string>'
    ],
    'allow_all_scopes' => true
  ]),
  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;
}
HttpResponse<String> response = Unirest.post("https://{tenantDomain}/api/v2/client-grants")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"audience\": \"<string>\",\n  \"client_id\": \"<string>\",\n  \"default_for\": \"third_party_clients\",\n  \"allow_any_organization\": false,\n  \"scope\": [\n    \"<string>\"\n  ],\n  \"authorization_details_types\": [\n    \"<string>\"\n  ],\n  \"allow_all_scopes\": true\n}")
  .asString();
require 'uri'
require 'net/http'

url = URI("https://{tenantDomain}/api/v2/client-grants")

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  \"audience\": \"<string>\",\n  \"client_id\": \"<string>\",\n  \"default_for\": \"third_party_clients\",\n  \"allow_any_organization\": false,\n  \"scope\": [\n    \"<string>\"\n  ],\n  \"authorization_details_types\": [\n    \"<string>\"\n  ],\n  \"allow_all_scopes\": true\n}"

response = http.request(request)
puts response.read_body
{
  "id": "<string>",
  "client_id": "<string>",
  "audience": "<string>",
  "scope": [
    "<string>"
  ],
  "allow_any_organization": true,
  "default_for": "third_party_clients",
  "is_system": true,
  "authorization_details_types": [
    "<string>"
  ],
  "allow_all_scopes": true
}

Autorisations

Authorization
string
header
requis

Bearer authentication header of the form Bearer <token>, where <token> is your auth token.

Corps

audience
string
requis

The audience (API identifier) of this client grant

Minimum string length: 1
client_id
string

ID of the client.

default_for
enum<string>
GA

Applies this client grant as the default for all clients in the specified group. The only accepted value is third_party_clients, which applies the grant to all third-party clients. Per-client grants for the same audience take precedence. Mutually exclusive with client_id.

Options disponibles:
third_party_clients
organization_usage
enum<string>

Defines whether organizations can be used with client credentials exchanges for this grant.

Options disponibles:
deny,
allow,
require
allow_any_organization
boolean
défaut:false

If enabled, any organization can be used with this grant. If disabled (default), the grant must be explicitly assigned to the desired organizations.

scope
string[]

Scopes allowed for this client grant.

Required string length: 1 - 280
subject_type
enum<string>

The type of application access the client grant allows.

Options disponibles:
client,
user
authorization_details_types
string[]

Types of authorization_details allowed for this client grant.

Required string length: 1 - 255
allow_all_scopes
boolean

If enabled, all scopes configured on the resource server are allowed for this grant.

Réponse

Client grant successfully created.

id
string

ID of the client grant.

client_id
string

ID of the client.

audience
string

The audience (API identifier) of this client grant.

Minimum string length: 1
scope
string[]

Scopes allowed for this client grant.

Minimum string length: 1
organization_usage
enum<string>

Defines whether organizations can be used with client credentials exchanges for this grant.

Options disponibles:
deny,
allow,
require
allow_any_organization
boolean

If enabled, any organization can be used with this grant. If disabled (default), the grant must be explicitly assigned to the desired organizations.

default_for
enum<string>
GA

Applies this client grant as the default for all clients in the specified group. The only accepted value is third_party_clients, which applies the grant to all third-party clients. Per-client grants for the same audience take precedence. Mutually exclusive with client_id.

Options disponibles:
third_party_clients
is_system
boolean

If enabled, this grant is a special grant created by Auth0. It cannot be modified or deleted directly.

subject_type
enum<string>

The type of application access the client grant allows.

Options disponibles:
client,
user
authorization_details_types
string[]

Types of authorization_details allowed for this client grant.

Required string length: 1 - 255
allow_all_scopes
boolean

If enabled, all scopes configured on the resource server are allowed for this grant.