Passer au contenu principal
PUT
https://{tenantDomain}/api/v2
/
users
/
{id}
/
authentication-methods
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.SetUserAuthenticationMethods{
        &management.SetUserAuthenticationMethods{
            Type: management.AuthenticationTypeEnumPhone,
        },
    }
    client.Users.AuthenticationMethods.Set(
        context.TODO(),
        "id",
        request,
    )
}
import { ManagementClient } from "auth0";

async function main() {
    const client = new ManagementClient({
        token: "<token>",
    });
    await client.users.authenticationMethods.set("id", [
        {
            type: "phone",
        },
    ]);
}
main();
import { ManagementClient } from "auth0";

async function main() {
    const client = new ManagementClient({
        token: "<token>",
    });
    await client.users.authenticationMethods.set("id", [
        {
            type: "phone",
        },
    ]);
}
main();
curl --request PUT \
  --url https://{tenantDomain}/api/v2/users/{id}/authentication-methods \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '
[
  {
    "name": "<string>",
    "phone_number": "<string>",
    "email": "<string>",
    "totp_secret": "<string>"
  }
]
'
import requests

url = "https://{tenantDomain}/api/v2/users/{id}/authentication-methods"

payload = [
    {
        "name": "<string>",
        "phone_number": "<string>",
        "email": "<string>",
        "totp_secret": "<string>"
    }
]
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

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

print(response.text)
<?php

$curl = curl_init();

curl_setopt_array($curl, [
  CURLOPT_URL => "https://{tenantDomain}/api/v2/users/{id}/authentication-methods",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "PUT",
  CURLOPT_POSTFIELDS => json_encode([
    [
        'name' => '<string>',
        'phone_number' => '<string>',
        'email' => '<string>',
        'totp_secret' => '<string>'
    ]
  ]),
  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.put("https://{tenantDomain}/api/v2/users/{id}/authentication-methods")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("[\n  {\n    \"name\": \"<string>\",\n    \"phone_number\": \"<string>\",\n    \"email\": \"<string>\",\n    \"totp_secret\": \"<string>\"\n  }\n]")
  .asString();
require 'uri'
require 'net/http'

url = URI("https://{tenantDomain}/api/v2/users/{id}/authentication-methods")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Put.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "[\n  {\n    \"name\": \"<string>\",\n    \"phone_number\": \"<string>\",\n    \"email\": \"<string>\",\n    \"totp_secret\": \"<string>\"\n  }\n]"

response = http.request(request)
puts response.read_body
[
  {
    "id": "<string>",
    "name": "<string>",
    "totp_secret": "<string>",
    "phone_number": "<string>",
    "email": "<string>",
    "authentication_methods": [
      {
        "id": "<string>"
      }
    ],
    "key_id": "<string>",
    "public_key": "<string>",
    "aaguid": "<string>",
    "relying_party_identifier": "<string>",
    "created_at": "2023-11-07T05:31:56Z"
  }
]

Autorisations

Authorization
string
header
requis

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

Paramètres de chemin

id
string
requis

The ID of the user in question.

Corps

type
enum<string>
requis
Options disponibles:
phone,
email,
totp
preferred_authentication_method
enum<string>

Applies to phone authentication methods only. The preferred communication method.

Options disponibles:
voice,
sms
name
string

AA human-readable label to identify the authentication method.

Required string length: 1 - 20
phone_number
string

Applies to phone authentication methods only. The destination phone number used to send verification codes via text and voice.

Required string length: 2 - 30
email
string

Applies to email authentication methods only. The email address used to send verification messages.

Minimum string length: 1
totp_secret
string

Applies to totp authentication methods only. The base32 encoded secret for TOTP generation.

Minimum string length: 1

Réponse

All authentication methods successfully updated.

type
enum<string>
requis
Options disponibles:
phone,
email,
totp,
webauthn-roaming
id
string<authenticator-id>

The ID of the newly created authentication method (automatically generated by the application)

name
string

A human-readable label to identify the authentication method.

totp_secret
string

Base32 encoded secret for TOTP generation

phone_number
string

Applies to phone authentication methods only. The destination phone number used to send verification codes via text and voice.

Required string length: 2 - 30
email
string

Applies to email authentication methods only. The email address used to send verification messages.

authentication_methods
object[]
preferred_authentication_method
enum<string>

Preferred phone authentication method

Options disponibles:
voice,
sms
key_id
string

Applies to webauthn authenticators only. The id of the credential.

public_key
string

Applies to webauthn authenticators only. The public key.

aaguid
string

Applies to passkeys only. Authenticator Attestation Globally Unique Identifier.

relying_party_identifier
string

Applies to webauthn authenticators only. The relying party identifier.

created_at
string<date-time>

Authentication method creation date