ユーザー名/パスワード
最小 SDK バージョン: 2.7.2
ユーザー名/パスワードを使用してゲーム内でのプレイヤーの認証を設定する以下のシナリオについて説明します。
- ユーザー名/パスワードを設定する。
- 戻ってきたプレイヤーをサインインする、または新しいプレイヤーを作成する。
- プレイヤーを匿名ログインからユーザー名/パスワードのアカウントを介したプラットフォームログインへと更新する。
ノート:最初に SDK を 初期化 する必要があります。
ユーザー名/パスワードの設定
- Unity Authentication について、ID プロバイダーをユーザー名/パスワードに設定します。
- Unity エディターメニューで、Edit (編集) > Project Settings... (プロジェクト設定...) に移動し、Services (サービス) > Authentication を選択します。
- ID Providers (ID プロバイダー) を Username/Password (ユーザー名/パスワード) に設定し、Add (追加) を選択します。
- Save (保存) を選択します。
サインアップまたは戻ってきたプレイヤーのサインイン
ユーザー名/パスワードの認証情報を使用して新しいプレイヤーを作成するには、SignUpWithUsernamePasswordAsync
メソッドを使用します。
ノート 1: username (ユーザー名) では、大文字と小文字は区別されません。これは 3 文字以上 20 文字以下である必要があり、文字、数字、記号 (.、-、@、_ など) のみがサポートされます。ノート 2:password (パスワード) では、大文字と小文字が区別されます。これは 8 文字以上 30 文字以下であり、少なくとも小文字 1 つ、大文字 1 つ、数字 1 つ、記号 1 つを含んでいる必要があります。
async Task SignUpWithUsernamePasswordAsync(string username, string password)
{
try
{
await AuthenticationService.Instance.SignUpWithUsernamePasswordAsync(username, password);
Debug.Log("SignUp is successful.");
}
catch (AuthenticationException ex)
{
// Compare error code to AuthenticationErrorCodes
// Notify the player with the proper error message
Debug.LogException(ex);
}
catch (RequestFailedException ex)
{
// Compare error code to CommonErrorCodes
// Notify the player with the proper error message
Debug.LogException(ex);
}
}
ユーザー名/パスワードの認証情報を使用して既存のプレイヤーをサインインするには、SignInWithUsernamePasswordAsync
メソッドを使用します。
async Task SignInWithUsernamePasswordAsync(string username, string password)
{
try
{
await AuthenticationService.Instance.SignInWithUsernamePasswordAsync(username, password);
Debug.Log("SignIn is successful.");
}
catch (AuthenticationException ex)
{
// Compare error code to AuthenticationErrorCodes
// Notify the player with the proper error message
Debug.LogException(ex);
}
catch (RequestFailedException ex)
{
// Compare error code to CommonErrorCodes
// Notify the player with the proper error message
Debug.LogException(ex);
}
}
プレイヤーを匿名からユーザー名/パスワードアカウントへと更新する
匿名認証を設定した後、プレイヤーが匿名からアップグレードし、ユーザー名/パスワードのアカウントを作成してサインインすることを希望する場合は、プレイヤーに認証情報の入力を求めるプロンプトを表示します。AddUsernamePasswordAsync
API を呼び出して、新しいユーザー名/パスワードのアカウントを作成し、それをプレイヤーに追加します。
SDK にキャッシュされたプレイヤーが存在する場合は、新しいユーザー名/パスワードを作成し、それをキャッシュされたプレイヤーに追加します。
SignInAnonymouslyAsync
を使用して、キャッシュされたプレイヤーのアカウントをサインインします。AddUsernamePasswordAsync
を使用して、新しいアカウントを作成し、それをキャッシュされたプレイヤーのアカウントに追加します。
ノート: アカウントに追加した後にユーザー名/パスワードのアカウントを削除することはできません。
キャッシュされたプレイヤーについて詳しくは、キャッシュされたプレイヤーのサインイン を参照してください。
async Task AddUsernamePasswordAsync(string username, string password)
{
try
{
await AuthenticationService.Instance.AddUsernamePasswordAsync(username, password);
Debug.Log("Username and password added.");
}
catch (AuthenticationException ex)
{
// Compare error code to AuthenticationErrorCodes
// Notify the player with the proper error message
Debug.LogException(ex);
}
catch (RequestFailedException ex)
{
// Compare error code to CommonErrorCodes
// Notify the player with the proper error message
Debug.LogException(ex);
}
}
プレイヤーのパスワードの変更
プレイヤーに、ユーザー名/パスワードのアカウントのパスワードを変更するオプションを提供します。
ユーザーはサインイン済みである必要があり、ユーザーに 現在のパスワード と 新しいパスワード の入力をリクエストした後で、UpdatePasswordAsync
を呼び出す必要があります。UpdatePasswordAsync
ではユーザーの認証ステータスが保持されますが、他のすべてのサインイン済みデバイスでは、ユーザーはサインインし直すよう求められます。
ノート: UpdatePasswordAsync
の呼び出しが成功すると、ユーザーがキャッシュされていたすべてのデバイスからユーザーがサインアウトされます。
async Task UpdatePasswordAsync(string currentPassword, string newPassword)
{
try
{
await AuthenticationService.Instance.UpdatePasswordAsync(currentPassword, newPassword);
Debug.Log("Password updated.");
}
catch (AuthenticationException ex)
{
// Compare error code to AuthenticationErrorCodes
// Notify the player with the proper error message
Debug.LogException(ex);
}
catch (RequestFailedException ex)
{
// Compare error code to CommonErrorCodes
// Notify the player with the proper error message
Debug.LogException(ex);
}
}