ドキュメント

​
​

Development

User Acquisition

Monetization

産業

Authentication

Open Unity Dashboard

Authentication

LiveOps
​
​
Authentication
  • Overview
  • Get started
  • Concepts
  • Tutorials
    • Anonymous sign-in
    • Google Play Games
    • Apple Game Center
    • Steam
    • Facebook
    • Unity Player Accounts
    • Oculus
    • Username and Password
    • Code-Link
    • Google
    • Apple
    • Custom OpenID Connect
    • Custom ID
  • Reference
  • Privacy and consent
  1. Unity Authentication

Code-Link

Provide a Code Link sign-in option to enable account linking by sharing unique codes between devices.
読み終わるまでの所要時間 7 分
最終更新 9ヶ月前

最小 SDK バージョン: 3.0.0
Code-Link を使用してゲーム内でのプレイヤーの認証を設定する以下のシナリオについて説明します。
  • Code-Link を設定する。
  • Code-Link を使用してサインインする。

Code-Link の設定

  1. Unity Authentication について、ID プロバイダーを Code-Link に設定します。
    1. Unity エディターメニューで、Edit (編集) > Project Settings... (プロジェクト設定...) に移動し、Services (サービス) > Authentication を選択します。
    2. ID Providers (ID プロバイダー) を Code-Link に設定し、Add (追加) を選択します。
    3. Save (保存) を選択します。

Code-Link を使用したサインイン

以下の Code-Link の機能を使用して、プレイヤーとしてサインインします。
  1. プレイヤーは、匿名で、またはサポートされている ID プロバイダーのいずれかを使用して、デバイス A にサインインします。
  2. プレイヤーは (サインインしていない) デバイス B でも同じアカウントを使用することに決め、サインインコードの生成をデバイス B に要求します。
  3. サインインコードを受け取ったら、プレイヤーはそのコードをデバイス A に入力して、コードが承認されることを確認します。
  4. プレイヤーはデバイス B に戻り、コードによるサインインをリクエストします。
  5. デバイス B が、デバイス A と同じアカウントで認証されます。
注
ノート: デバイス B で、コードが承認されるか期限切れになるまでサービスのポーリングが行われる場合は、ステップ 4 をスキップできます。
Code-Link を使用したサインインを行うには、以下のステップに従います。
  1. 認証と サインインコード の生成を行いたい未認証のデバイスから、
    GenerateSignInCodeAsync
    メソッドを使用します (識別子を渡すことは任意ですが、サインインコードを生成したデバイスを識別するために推奨されます)。
  2. 生成されたサインインコードと有効期限をプレイヤーに表示します。
    注
    ノート: identifier (識別子) の長さは最大 128 文字です。
    async Task GenerateCodeAsync(string identifier){ try { var codeInfo = await AuthenticationService.Instance.GenerateSignInCodeAsync(identifier); // Display code, and expiration and identifier to the player } catch (Exception e) { // Notify the client something went wrong generating the code }}
  3. すでに認証済みの 2 つめのデバイスで、サインインコードを入力するためのアクセスをプレイヤーに許可します。
  4. (任意)
    GetSignInCodeInfoAsync
    を使用して、プレイヤーから提供されたサインインコードによってサインインコードの情報を取得し、プレイヤーに表示します。これにより、プレイヤーは両方のデバイスで識別子を比較して、正しいデバイスを認証しようとしていることを確認できます。
  5. ConfirmCodeAsync
    を使用して、Code-Link によるサインインを承認します。
    注
    ノート:
    ConfirmCodeAsync
    メソッドでは、選択可能なパラメーターとして idProvider と externalToken もサポートされています。これらのパラメーターはコンソールでのみ使用するようにしてください。コンソールクライアントから使用した場合は、エラーが返されます。
    async Task GetCodeInfoAsync(string signInCode){ try { var codeInfo = await AuthenticationService.Instance.GetSignInCodeInfoAsync(signInCode); // Display code, and expiration and identifier to the player and ask them to authorize the code-link sign in } catch (Exception e) { // Notify the client something went wrong getting the code information }}async Task ConfirmCodeAsync(string signInCode){try{await AuthenticationService.Instance.ConfirmCodeAsync(signInCode);// Display a confirmation that the device should be authorized}catch (Exception e){// Notify the client something went wrong with the code confirmation}}
  6. SignInWithCodeAsync
    を呼び出して、サインインコードを生成したのと同じデバイスでプレイヤーをサインインします (Code-Link によるサインインを認証するための認証情報はメモリに格納されているため、SignInWithCodeAsync を呼び出す前に必ず GenerateSignInCodeAsync を呼び出してください。これを行わない場合、例外がスローされます)。コードがまだ承認されていない場合、このメソッドは成功しますが、プレイヤーはサインインされません。サインインが成功したかどうかを確認するには、SignedIn イベントを探します。
    public async Task SignInWithCodeAsync(){ try { AuthenticationService.Instance.SignedIn += UserHasSignedIn await AuthenticationService.Instance.SignInWithCodeAsync(); } catch (Exception e) { // Notify the client something went wrong signing in the player } finally { AuthenticationService.Instance.SignedIn -= UserHasSignedIn }}public void UserHasSignedIn() { // Notify the client the user signed in successfully.}
<Note>**ノート**: `SignInWithCodeAsync` メソッドでも自動ポーリング (5 秒ごと) を実行できるため、コードが承認されるとデバイスでプレイヤーが自動的にサインインされ、コードが期限切れになると例外がスローされます。また、このメソッドはポーリングをキャンセルするための `CancellationToken` を受け入れます。```csCancellationTokenSource CodeLinkCancellationTokenSource;</Note>public async Task PollSignInWithCodeAsync()\{ try \{ CodeLinkCancellationTokenSource = new CancellationTokenSource(); await AuthenticationService.SignInWithCodeAsync(true, CodeLinkCancellationTokenSource.Token); } catch (Exception e) \{ // Notify the client something went wrong with Polling for Code Confirmation }}public void CancelSignInWithCode()\{ CodeLinkCancellationTokenSource.Cancel();}

Copyright © 2026 Unity Technologies
法規事項プライバシーポリシークッキーDocumentation Terms of Use私の個人情報を販売または共有しないプライバシーに関する選択 (クッキー設定)

"Unity" の名称、Unity のロゴ、およびその他の Unity の商標は、米国およびその他の国における Unity Technologies またはその関係会社の商標または登録商標です (詳しくはこちら)。その他の名称またはブランドは該当する所有者の商標です。

一部のページは利便性向上のため機械翻訳を使用しており、内容に不正確な表現が含まれる場合があります。内容に齟齬または不一致が生じた場合は、英語版を正本とします。

  • このページ
    • 最小 SDK バージョン: 3.0.0

    • Code-Link の設定

    • Code-Link を使用したサインイン


このページの問題を報告する