ユーザー名/パスワード
Provide a username and password option to enable players to authenticate using custom credentials in your game.
読み終わるまでの所要時間 2 分最終更新 1ヶ月前
最小 SDK バージョン: 2.7.2
ユーザー名/パスワードを使用してゲーム内でのプレイヤーの認証を設定する以下のシナリオについて説明します。- ユーザー名/パスワードを設定する。
- 戻ってきたプレイヤーをサインインする、または新しいプレイヤーを作成する。
- プレイヤーを匿名ログインからユーザー名/パスワードのアカウントを介したプラットフォームログインへと更新する。
ユーザー名/パスワードの設定
- Unity Authentication について、ID プロバイダーをユーザー名/パスワードに設定します。
- Unity エディターメニューで、Edit (編集) > Project Settings... (プロジェクト設定...) に移動し、Services (サービス) > Authentication を選択します。
- ID Providers (ID プロバイダー) を Username/Password (ユーザー名/パスワード) に設定し、Add (追加) を選択します。
- Save (保存) を選択します。
サインアップまたは戻ってきたプレイヤーのサインイン
ユーザー名/パスワードの認証情報を使用して新しいプレイヤーを作成するには、SignUpWithUsernamePasswordAsyncユーザー名/パスワードの認証情報を使用して既存のプレイヤーをサインインするには、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); }}
SignInWithUsernamePasswordAsyncasync 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- を使用して、キャッシュされたプレイヤーのアカウントをサインインします。
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); }}
プレイヤーのパスワードの変更
プレイヤーに、ユーザー名/パスワードのアカウントのパスワードを変更するオプションを提供します。 ユーザーはサインイン済みである必要があり、ユーザーに 現在のパスワード と 新しいパスワード の入力をリクエストした後で、UpdatePasswordAsyncUpdatePasswordAsyncasync 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); }}