> ## Documentation Index
> Fetch the complete documentation index at: https://translations.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

> Auth0 MFA API を使用して登録チケットを作成する方法を学びます。

# カスタム登録チケットを作成する

export const AuthCodeGroup = ({children, dropdown}) => {
  const [processedChildren, setProcessedChildren] = useState(children);
  useEffect(() => {
    let unsubscribe = null;
    function init() {
      unsubscribe = window.autorun(() => {
        const processChildren = node => {
          if (typeof node === "string") {
            let processedNode = node;
            for (const [key, value] of window.rootStore.variableStore.values.entries()) {
              const escapedKey = key.replaceAll(/[.*+?^${}()|[\]\\]/g, (String.raw)`\$&`);
              processedNode = processedNode.replaceAll(new RegExp(escapedKey, "g"), value);
            }
            return processedNode;
          } else if (Array.isArray(node)) {
            return node.map(processChildren);
          } else if (node && node.props && node.props.children) {
            return {
              ...node,
              props: {
                ...node.props,
                children: processChildren(node.props.children)
              }
            };
          }
          return node;
        };
        setProcessedChildren(processChildren(children));
      });
    }
    if (window.rootStore) {
      init();
    } else {
      window.addEventListener("adu:storeReady", init);
    }
    return () => {
      window.removeEventListener("adu:storeReady", init);
      unsubscribe?.();
    };
  }, [children]);
  return <CodeGroup dropdown={dropdown}>{processedChildren}</CodeGroup>;
};

export const AuthCodeBlock = ({filename, icon, language, highlight, children}) => {
  const [displayText, setDisplayText] = useState(children);
  const [copyText, setCopyText] = useState(children);
  const wrapperRef = React.useRef(null);
  useEffect(() => {
    let unsubscribe = null;
    function init() {
      if (!window.autorun || !window.rootStore) {
        return;
      }
      unsubscribe = window.autorun(() => {
        let processedChildrenForDisplay = children;
        let processedChildrenForCopy = children;
        for (const [key, value] of window.rootStore.variableStore.values.entries()) {
          const escapedKey = key.replaceAll(/[.*+?^${}()|[\]\\]/g, (String.raw)`\$&`);
          let displayValue = value;
          if (key === "{yourClientSecret}" && value !== "{yourClientSecret}") {
            displayValue = value.substring(0, 3) + "*****マスク済み*****";
          }
          processedChildrenForDisplay = processedChildrenForDisplay.replaceAll(new RegExp(escapedKey, "g"), displayValue);
          processedChildrenForCopy = processedChildrenForCopy.replaceAll(new RegExp(escapedKey, "g"), value);
        }
        setDisplayText(processedChildrenForDisplay);
        setCopyText(processedChildrenForCopy);
      });
    }
    if (window.rootStore) {
      init();
    } else {
      window.addEventListener("adu:storeReady", init);
    }
    return () => {
      window.removeEventListener("adu:storeReady", init);
      unsubscribe?.();
    };
  }, [children]);
  useEffect(() => {
    if (!wrapperRef.current) return;
    const originalWriteText = navigator.clipboard.writeText.bind(navigator.clipboard);
    let isOverriding = false;
    const handleClick = e => {
      const button = e.target.closest('[data-testid="copy-code-button"]');
      if (!button || !wrapperRef.current.contains(button)) return;
      isOverriding = true;
      navigator.clipboard.writeText = text => {
        if (isOverriding) {
          isOverriding = false;
          navigator.clipboard.writeText = originalWriteText;
          return originalWriteText(copyText);
        }
        return originalWriteText(text);
      };
      setTimeout(() => {
        if (isOverriding) {
          isOverriding = false;
          navigator.clipboard.writeText = originalWriteText;
        }
      }, 100);
    };
    const wrapper = wrapperRef.current;
    wrapper.addEventListener('click', handleClick, true);
    return () => {
      wrapper.removeEventListener('click', handleClick, true);
      if (navigator.clipboard.writeText !== originalWriteText) {
        navigator.clipboard.writeText = originalWriteText;
      }
    };
  }, [copyText]);
  return <div ref={wrapperRef}>
      <CodeBlock filename={filename} icon={icon} language={language} lines highlight={highlight}>
        {displayText}
      </CodeBlock>
    </div>;
};

ユーザーの [多要素認証 (MFA) ](/ja/docs/secure/multi-factor-authentication) の登録をカスタマイズして管理するには、カスタム登録チケット を使用できます。Auth0 の カスタム登録チケット では、指定した [要素](/ja/docs/secure/multi-factor-authentication/multi-factor-authentication-factors) を使用してユーザーを <Tooltip tip="多要素認証（MFA）: SMS による code など、username とパスワードに加えて別の要素を使用するユーザー認証プロセス。" cta="用語集を表示" href="/ja/docs/glossary?term=MFA">MFA</Tooltip> に登録するための 1 回限り有効なリンクを生成できます。

<div id="use-cases">
  ### 使用例
</div>

カスタム登録チケット は、次のような用途で使用します。

* 新規ユーザーのオンボーディング
* ユーザー設定の構成
* 登録時に顧客が選択する認証要素の指定
* ユーザーが複数の認証要素を登録できるようにすること

<div id="configure-custom-enrollment-tickets">
  ### カスタム登録チケットを設定する
</div>

<Tooltip tip="Management API: 顧客が管理タスクを実行するための製品。" cta="用語集を表示" href="/ja/docs/glossary?term=Management+API">Management API</Tooltip> の [`/guardian/post_ticket`](https://auth0.com/docs/api/management/v2#!/Guardian/post_ticket) エンドポイントに POST リクエストを送信します。

<AuthCodeGroup>
  ```bash cURL theme={null}
  curl --request POST \
    --url 'https://{yourDomain}/api/v2/guardian/post-ticket' \
    --header 'authorization: Bearer {yourMgmtApiAccessToken}' \
    --header 'content-type: application/json' \
    --data '{ 
   "user_id": "string",
   "email": "user@exampleco.com",
   "send_email": "true",
   "email_locale": "string",
   "factor": "oob",
   "allow_multiple_enrollments": "true"
   }'
  ```

  ```csharp C# theme={null}
  var client = new RestClient("https://{yourDomain}/api/v2/guardian/post-ticket");
  var request = new RestRequest(Method.POST);
  request.AddHeader("authorization", "Bearer {yourMgmtApiAccessToken}");
  request.AddHeader("content-type", "application/json");
  request.AddParameter("application/json", "{ 
   "user_id": "string",
   "email": "user@exampleco.com",
   "send_email": "true",
   "email_locale": "string",
   "factor": "oob",
   "allow_multiple_enrollments": "true"
   }", ParameterType.RequestBody);
  IRestResponse response = client.Execute(request);
  ```

  ```go Go theme={null}
  package main

  import (
  	"fmt"
  	"strings"
  	"net/http"
  	"io/ioutil"
  )

  func main() {

  	url := "https://{yourDomain}/api/v2/guardian/post-ticket"

  	payload := strings.NewReader("{ 
   "user_id": "string",
   "email": "user@exampleco.com",
   "send_email": "true",
   "email_locale": "string",
   "factor": "oob",
   "allow_multiple_enrollments": "true"
   }")

  	req, _ := http.NewRequest("POST", url, payload)

  	req.Header.Add("authorization", "Bearer {yourMgmtApiAccessToken}")
  	req.Header.Add("content-type", "application/json")

  	res, _ := http.DefaultClient.Do(req)

  	defer res.Body.Close()
  	body, _ := ioutil.ReadAll(res.Body)

  	fmt.Println(res)
  	fmt.Println(string(body))

  }
  ```

  ```java Java theme={null}
  HttpResponse<String> response = Unirest.post("https://{yourDomain}/api/v2/guardian/post-ticket")
    .header("authorization", "Bearer {yourMgmtApiAccessToken}")
    .header("content-type", "application/json")
    .body("{ 
   "user_id": "string",
   "email": "user@exampleco.com",
   "send_email": "true",
   "email_locale": "string",
   "factor": "oob",
   "allow_multiple_enrollments": "true"
   }")
    .asString();
  ```

  ```javascript Node.JS theme={null}
  var axios = require("axios").default;

  var options = {
    method: 'POST',
    url: 'https://{yourDomain}/api/v2/guardian/post-ticket',
    headers: {
      authorization: 'Bearer {yourMgmtApiAccessToken}',
      'content-type': 'application/json'
    },
    data: {
      user_id: 'string',
      email: 'user@exampleco.com',
      send_email: 'true',
      email_locale: 'string',
      factor: 'oob',
      allow_multiple_enrollments: 'true'
    }
  };

  axios.request(options).then(function (response) {
    console.log(response.data);
  }).catch(function (error) {
    console.error(error);
  });
  ```

  ```php PHP theme={null}
  $curl = curl_init();

  curl_setopt_array($curl, [
    CURLOPT_URL => "https://{yourDomain}/api/v2/guardian/post-ticket",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_ENCODING => "",
    CURLOPT_MAXREDIRS => 10,
    CURLOPT_TIMEOUT => 30,
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    CURLOPT_CUSTOMREQUEST => "POST",
    CURLOPT_POSTFIELDS => "{ 
   "user_id": "string",
   "email": "user@exampleco.com",
   "send_email": "true",
   "email_locale": "string",
   "factor": "oob",
   "allow_multiple_enrollments": "true"
   }",
    CURLOPT_HTTPHEADER => [
      "authorization: Bearer {yourMgmtApiAccessToken}",
      "content-type: application/json"
    ],
  ]);

  $response = curl_exec($curl);
  $err = curl_error($curl);

  curl_close($curl);

  if ($err) {
    echo "cURL Error #:" . $err;
  } else {
    echo $response;
  }
  ```

  ```python Python theme={null}
  import http.client

  conn = http.client.HTTPSConnection("")

  payload = "{ 
   "user_id": "string",
   "email": "user@exampleco.com",
   "send_email": "true",
   "email_locale": "string",
   "factor": "oob",
   "allow_multiple_enrollments": "true"
   }"

  headers = {
      'authorization': "Bearer {yourMgmtApiAccessToken}",
      'content-type': "application/json"
      }

  conn.request("POST", "/{yourDomain}/api/v2/guardian/post-ticket", payload, headers)

  res = conn.getresponse()
  data = res.read()

  print(data.decode("utf-8"))
  ```

  ```ruby Ruby theme={null}
  require 'uri'
  require 'net/http'
  require 'openssl'

  url = URI("https://{yourDomain}/api/v2/guardian/post-ticket")

  http = Net::HTTP.new(url.host, url.port)
  http.use_ssl = true
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE

  request = Net::HTTP::Post.new(url)
  request["authorization"] = 'Bearer {yourMgmtApiAccessToken}'
  request["content-type"] = 'application/json'
  request.body = "{ 
   "user_id": "string",
   "email": "user@exampleco.com",
   "send_email": "true",
   "email_locale": "string",
   "factor": "oob",
   "allow_multiple_enrollments": "true"
   }"

  response = http.request(request)
  puts response.read_body
  ```
</AuthCodeGroup>

| パラメーター                       | 必須 | 説明                                                                                            |
| ---------------------------- | -- | --------------------------------------------------------------------------------------------- |
| `allow_multiple_enrollments` | 任意 | すでに登録済みのユーザーが、メールアドレスを除く追加の認証要素を登録できるようにします。                                                  |
| `factor`                     | 任意 | ユーザーに登録させる認証要素を指定します (メールアドレスを除く) 。`allow_multiple_enrollments` と併用すると、登録対象として複数の認証要素を指定できます。 |

<Callout icon="file-lines" color="#0EA5E9" iconType="regular">
  これらのパラメーターは [Universal Login](/ja/docs/authenticate/login/auth0-universal-login) でのみ使用でき、クラシックログイン やカスタム MFA ページでは使用できません。
</Callout>

Management API は、`ticket_id` と `ticket_url` を含む登録チケットを返します。`ticket_id` は内部使用専用です。`send_email` パラメーターを使用して `ticket_url` をユーザーに送信し、登録プロセスを開始します。チケットの有効期限は 5 日間で、1 回しか使用できません。チケットを受け取ったユーザーは、一度だけ登録できます。

レスポンス例:

```json lines theme={null}
{
  "ticket_id": "gten_8b2f5e90d2c848dc9230d34f",
  "ticket_url": "https://guardianadnrdoifcmtest0.eu.auth0.com/guardian/enroll?ticket=gten_8b2f5e90d2c848dc9230d34f"
}
```

[Multiple Custom Domains](/ja/docs/customize/custom-domains/multiple-custom-domains) を有効にしている場合は、HTTP ヘッダー `auth0-custom-domain` を含める必要があります。詳しくは、[Multiple Custom Domains](/ja/docs/customize/custom-domains/multiple-custom-domains#customize-email-handling-using-the-management-api) を参照してください。

<div id="custom-enrollment-tickets-with-classic-login">
  ### クラシックログインでのカスタム登録チケット
</div>

[クラシックログイン](/ja/docs/authenticate/login/auth0-universal-login/universal-login-vs-classic-login/classic-experience) を使用していて、ユーザーが `ticket_url` にアクセスしたときに表示されるページの見た目をカスタマイズする必要がある場合は、MFA ページを編集できます。

1. [Dashboard > ブランディング > Universal Login > 詳細オプション > 多要素認証](https://manage.auth0.com/#/mfa_page) に移動します。
2. **Customize MFA Page** が選択されていない場合は、このオプションをオンにします。
3. `ticket` 変数を更新します。
   例:

```liquid lines theme={null}
{% if ticket %}
<h4 class="message">Welcome, {{ userData.email }}, enroll your device below</h4>
{% else %}
<h4 class="message">Welcome back, {{ userData.email }}, authenticate below</h4>
{% endif %}
```

<div id="learn-more">
  ## 関連情報
</div>

* [MFA ウィジェットのテーマオプション](/ja/docs/secure/multi-factor-authentication/customize-mfa/mfa-widget-theme-options)
* [Guardian エラーコード リファレンス](/ja/docs/secure/multi-factor-authentication/multi-factor-authentication-developer-resources/guardian-error-code-reference)
* [Auth0 MFA API](/ja/docs/secure/multi-factor-authentication/multi-factor-authentication-developer-resources/mfa-api)
