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.CreateHookRequestContent{
Name: "name",
Script: "script",
TriggerId: management.HookTriggerIdEnumCredentialsExchange,
}
client.Hooks.Create(
context.TODO(),
request,
)
}
import { ManagementClient } from "auth0";
async function main() {
const client = new ManagementClient({
token: "<token>",
});
await client.hooks.create({
name: "name",
script: "script",
triggerId: "credentials-exchange",
});
}
main();
import { ManagementClient } from "auth0";
async function main() {
const client = new ManagementClient({
token: "<token>",
});
await client.hooks.create({
name: "name",
script: "script",
triggerId: "credentials-exchange",
});
}
main();
curl --request POST \
--url https://{tenantDomain}/api/v2/hooks \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"name": "my-hook",
"script": "module.exports = function(client, scope, audience, context, cb) cb(null, access_token); };",
"enabled": false,
"dependencies": {}
}
'import requests
url = "https://{tenantDomain}/api/v2/hooks"
payload = {
"name": "my-hook",
"script": "module.exports = function(client, scope, audience, context, cb) cb(null, access_token); };",
"enabled": False,
"dependencies": {}
}
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/hooks",
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([
'name' => 'my-hook',
'script' => 'module.exports = function(client, scope, audience, context, cb) cb(null, access_token); };',
'enabled' => false,
'dependencies' => [
]
]),
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/hooks")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"name\": \"my-hook\",\n \"script\": \"module.exports = function(client, scope, audience, context, cb) cb(null, access_token); };\",\n \"enabled\": false,\n \"dependencies\": {}\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://{tenantDomain}/api/v2/hooks")
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 \"name\": \"my-hook\",\n \"script\": \"module.exports = function(client, scope, audience, context, cb) cb(null, access_token); };\",\n \"enabled\": false,\n \"dependencies\": {}\n}"
response = http.request(request)
puts response.read_body{
"triggerId": "<string>",
"id": "00001",
"name": "hook",
"enabled": true,
"script": "module.exports = function(client, scope, audience, context, cb) cb(null, access_token); };",
"dependencies": {}
}Create a hook
Create a new hook.
POST
https://{tenantDomain}/api/v2
/
hooks
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.CreateHookRequestContent{
Name: "name",
Script: "script",
TriggerId: management.HookTriggerIdEnumCredentialsExchange,
}
client.Hooks.Create(
context.TODO(),
request,
)
}
import { ManagementClient } from "auth0";
async function main() {
const client = new ManagementClient({
token: "<token>",
});
await client.hooks.create({
name: "name",
script: "script",
triggerId: "credentials-exchange",
});
}
main();
import { ManagementClient } from "auth0";
async function main() {
const client = new ManagementClient({
token: "<token>",
});
await client.hooks.create({
name: "name",
script: "script",
triggerId: "credentials-exchange",
});
}
main();
curl --request POST \
--url https://{tenantDomain}/api/v2/hooks \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"name": "my-hook",
"script": "module.exports = function(client, scope, audience, context, cb) cb(null, access_token); };",
"enabled": false,
"dependencies": {}
}
'import requests
url = "https://{tenantDomain}/api/v2/hooks"
payload = {
"name": "my-hook",
"script": "module.exports = function(client, scope, audience, context, cb) cb(null, access_token); };",
"enabled": False,
"dependencies": {}
}
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/hooks",
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([
'name' => 'my-hook',
'script' => 'module.exports = function(client, scope, audience, context, cb) cb(null, access_token); };',
'enabled' => false,
'dependencies' => [
]
]),
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/hooks")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"name\": \"my-hook\",\n \"script\": \"module.exports = function(client, scope, audience, context, cb) cb(null, access_token); };\",\n \"enabled\": false,\n \"dependencies\": {}\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://{tenantDomain}/api/v2/hooks")
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 \"name\": \"my-hook\",\n \"script\": \"module.exports = function(client, scope, audience, context, cb) cb(null, access_token); };\",\n \"enabled\": false,\n \"dependencies\": {}\n}"
response = http.request(request)
puts response.read_body{
"triggerId": "<string>",
"id": "00001",
"name": "hook",
"enabled": true,
"script": "module.exports = function(client, scope, audience, context, cb) cb(null, access_token); };",
"dependencies": {}
}承認
bearerAuthoAuth2ClientCredentials
Bearer authentication header of the form Bearer <token>, where <token> is your auth token.
ボディ
application/jsonapplication/x-www-form-urlencoded
Name of this hook.
Pattern:
^[a-zA-Z0-9]([ \-a-zA-Z0-9]*[a-zA-Z0-9])?$script
string
デフォルト:module.exports = function(client, scope, audience, context, cb) cb(null, access_token); };
必須
Code to be executed when this hook runs.
Minimum string length:
1Execution stage of this rule. Can be credentials-exchange, pre-user-registration, post-user-registration, post-change-password, or send-phone-message.
利用可能なオプション:
credentials-exchange, pre-user-registration, post-user-registration, post-change-password, send-phone-message Whether this hook will be executed (true) or ignored (false).
Dependencies of this hook used by webtask server.
Show child attributes
Show child attributes
レスポンス
Hook successfully created.
Trigger ID
ID of this hook.
Name of this hook.
Whether this hook will be executed (true) or ignored (false).
script
string
デフォルト:module.exports = function(client, scope, audience, context, cb) cb(null, access_token); };
Code to be executed when this hook runs.
Dependencies of this hook used by webtask server.
Show child attributes
Show child attributes
⌘I