- Login
- Verifying Authentication Token Key
- Detecting Changes in IdP Account in the Background
- Logout
- Notification phrases for Game Center Sign-in Disabled
Login
Login in authentication is composed of the following steps.
Following image is a flow chart of authentication composed of the steps above.
Refer to the following notes to implement the login function.
Automatic Login
Authentication returns a token key based on login authentication for all users, regardless of IdP type. If this key exists, execute Automatic Login.
Check whether it is possible to automatically sign in by using Automatic Login possibility returned after initializing HIVE SDK or calling isAutoSignIn()
. If the value of isAutoSignIn()
is true
, call signIn()
with the parameter, ProviderType.AUTO
to carry out Automatic Login.
Followings are sample codes to execute Automatic Login.
API Reference: hive.AuthV4.signIn
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
// Check whether HIVE SDK AuthV4 auto signin // HIVE SDK AuthV4 Auth callback handler public void onAuthV4SignIn(ResultAPI result, AuthV4.PlayerInfo playerInfo) { if (result.isSuccess() == true) { // Success signin // playerInfo : signin user info. } } // If isAutoSignIn is true, you must try auto signin Boolean isAutoSignIn = AuthV4.isAutoSignIn(); if (isAutoSignIn == true) { AuthV4.signIn(AuthV4.ProviderType.AUTO, onAuthV4SignIn); } else { // TODO : Try implicit login using Google Play Game Service account/Apple Game Center or flow explicit login // ex) AuthV4.signIn(AuthV4.ProviderType.GOOGLE, onAuthV4SignIn); // ex) AuthV4.showSignIn(); } |
API Reference: Auth4::signIn
1 2 3 4 5 6 7 8 |
// Whether HIVE SDK AuthV4 auto signin bool isAutoSignIn = AuthV4::isAutoSignIn(); if (isAutoSignIn) { AuthV4::signIn(ProviderType::AUTO, [=](ResultAPI const & result,PlayerInfo const & playerInfo){}); } else { // TODO : Try implicit login using Google Play Game Service account/Apple Game Center or flow explicit login } |
API Reference: com.hive.Auth4.signIn
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
//Check whether HIVE SDK AuthV4 auto login //If isAutoSignIn is true, you must try auto signin boolean isAutoSignIn = AuthV4.isAutoSignIn(); if (isAutoSignIn) { AuthV4.signIn(AuthV4.ProviderType.AUTO, new AuthV4.AuthV4SignInListener() { @Override public void onAuthV4SignIn(ResultAPI result, AuthV4.PlayerInfo playerInfo) { } }); } else { // TODO : Implicitly attempt to sign in to Google Play Games or Apple Game Center or go to an explicit login // ex) AuthV4.signIn(AuthV4.ProviderType.APPLE, onAuthV4SignInListener); // ex) AuthV4.showSignIn(); } |
API Reference: HIVEAuth4:signIn
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
// Check whether HIVE SDK AuthV4 auto login // If isAutoSignIn is true, you must try auto signin BOOL isAutoSignIn = [HIVEAuthV4 isAutoSignIn]; if (isAutoSignIn) { // Try HIVE SDK signIn [HIVEAuthV4 signIn:kHIVEProviderTypeAUTO handler:^(HIVEResultAPI *result, HIVEPlayerInfo *playerInfo) { Loggerd(@"HIVEAuthV4.signIn:handler:\nresult = %@\nplayerInfo = %@", result, playerInfo); if (!result.isSuccess) { return; } }]; } else { // TODO : Try implicit login using Google Play Game Service account/Apple Game Center or flow explicit login // ex) // [HIVEAuthV4 signIn:kHIVEProviderTypeAPPLE handler:^(HIVEResultAPI *result, HIVEPlayerInfo *playerInfo) { // // do something... // }]; // // ex) // [HIVEAuthV4 showSignIn:^(HIVEResultAPI *result, HIVEPlayerInfo *playerInfo) { // // do something... // }]; } |
Checking Logged-in IdP Account on Device
Automatic Login allows to sign in only with authentication token key of stored PlayerId in the device, so the IdP account of PlayerID that is logged in may differ from the IdP account that is logged in the actual device. The IdP account logged in on the device is available to check by calling checkProvider()
. The IdP account of PlayerID currently logged in is called CurrentPlayer, and the IdP account logged in to the actual device is called DevicePlayer.
When the following conditions are satisfied after Automatic Login, call checkProvider()
.
-
- When the logged in PlayerID is connected with Apple Game Center based on the iOS apps
- When the logged in PlayerID is connected with Google Play Games based on the Android apps except for the users using Chinese IP
You should compares DevicePlayer and CurrentPlayer returned as a result of checkProvider()
in the game and configures the UI for users to choose whether to use the DevicePlayer if DevicePlayer and CurrentPlayer are not matched. If the user chooses DevicePlayer, you must call signOut
for CurrentPlayer to log out, and then executes Implicit Login. If the checkProvider () call fails or both accounts are the same, you can stay in auto-login status and enter the game.
- An example screen asking to use DevicePlayer or not
Followings are sample codes to confirm the IdP information.
API Reference: hive.AuthV4.checkProvider
1 2 3 4 5 6 7 8 9 10 11 12 |
public void onDeviceProviderInfo(ResultAPI result, AuthV4.ProviderInfo providerInfo) { if (result.isSuccess() != true) { // Fail to check IdP Info return; } } // Set PrividerType that you want check AuthV4.ProviderType providerType = AuthV4.ProviderType.GOOGLE; // Request HIVE SDK AuthV4 IdP info. AuthV4.checkProvider(providerType, onDeviceProviderInfo); |
API Reference:AuthV4.checkProvider
1 2 3 4 5 6 7 |
ProviderType targetProviderType = ProviderType::GOOGLE; AuthV4::checkProvider(targetProviderType, [=](ResultAPI const & result,ProviderInfo const & providerInfo){ if(result.isSuccess()) { //Compare account that logged in device with playerInfo's providerUserId } }); |
API Reference: com.hive.AuthV4.checkProvider
1 2 3 4 5 6 7 8 9 |
// Set ProviderType what you want to check ProviderType providerType = AuthV4.ProviderType.GOOGLE; AuthV4.checkProvider(providerType, new AuthV4.AuthV4CheckProviderListener() { @Override public void onDeviceProviderInfo(ResultAPI result, AuthV4.ProviderInfo providerInfo) { //Compare account that logged in device with playerInfo's providerUserId } }); |
API Reference: HIVEAuthV4:checkProvider
1 2 3 4 |
HIVEProviderType providerType = kHIVEProviderTypeAPPLE; [HIVEAuthV4 checkProvider:providerType handler:^(HIVEResultAPI *result, HIVEProviderInfo *providerInfo) { NSLog(@"result - %@\n\n\tproviderInfo - %@}", result, providerInfo); }]; |
Implicit Login
Implicit Login is a method that the user does not select a means of login, but logs in the Apple Game Center account on iOS or the Google Play Games account on Android automatically. Implement Automatic login, and if the automatic login fails, perform Implicit login.
After successful Implicit Login, implement the function to make users go to the game title screen and tap the title to enter the game lobby.
An example screen of Implicit Login
Implement signIn()
method with the parameter, ProviderType.APPLE
for iOS, and ProviderType.GOOGLE
for Android (Google Build) to execute Implicit Login.
Followings are sample codes to execute Implicit Login.
API Reference: hive.AuthV4.signIn
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
// HIVE SDK AuthV4 implicit login // HIVE SDK AuthV4 Auth UI callback handler public void onAuthV4SignIn(ResultAPI result, AuthV4.PlayerInfo playerInfo) { if (result.isSuccess() == true) { // sign in success // playerInfo : sign in user info. } else { // flow explicit login } } // Whether HIVE SDK AuthV4 auto singin Boolean isAutoSignIn = AuthV4.isAutoSignIn(); // If isAutoSignIn is true, you must try auto signin if (isAutoSignIn == true) { AuthV4.signIn(AuthV4.ProviderType.AUTO, onAuthV4SignIn); } else { // ex) Implicit login using Google Play Game account AuthV4.signIn(AuthV4.ProviderType.GOOGLE, onAuthV4SignIn); } |
API Reference: Auth4::signIn
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
// HIVE SDK AuthV4 implicit login // HIVE SDK AuthV4 Check whether automatic login is possible bool isAutoSignIn = AuthV4::isAutoSignIn(); if (isAutoSignIn) { AuthV4::signIn(ProviderType::AUTO, [=](ResultAPI const & result, PlayerInfo const & playerInfo){}); } else { // Try login with iOS - Apple GameCenter account AuthV4::signIn(ProviderType::APPLE, [=](ResultAPI const & result, PlayerInfo const & playerInfo) { if (result.isSuccess()) { cout<<"PlayerName : " << playerInfo.playerName << endl; cout<<"PlayerId : " << playerInfo.playerId << endl; } else { // TODO : Error Handling // Flow explicit login } }); // Android - try signin as Google Play Game account AuthV4::signIn(ProviderType::GOOGLE, [=](ResultAPI const & result, PlayerInfo const & playerInfo){ if (result.isSuccess()) { cout<<"PlayerName : " << playerInfo.playerName << endl; cout<<"PlayerId : " << playerInfo.playerId << endl; } else { // TODO : Error Handling // Flow explicit login } }); } |
API Reference: com.hive.Auth4.signIn
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
//Check whether HIVE SDK AuthV4 auto sign in //If isAutoSignIn is true, you must signIn with AUTO boolean isAutoSignIn = AuthV4.isAutoSignIn(); if (isAutoSignIn) { AuthV4.signIn(AuthV4.ProviderType.AUTO, new AuthV4.AuthV4SignInListener() { @Override public void onAuthV4SignIn(ResultAPI result, AuthV4.PlayerInfo playerInfo) { if (result.isSuccess()) { //Compare playerInfo's providerUserId to the actual devuce login ID AuthV4.checkProvider(providerType, onAuthV4CheckProviderListener); } } }); } else { // Google- Try to login with Google Play Game account AuthV4.signIn(AuthV4.ProviderType.GOOGLE, onAuthV4SignInListener); } |
API Reference: HIVEAuth4:signIn
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
// Check whether HIVE SDK AuthV4 auto sign in // If isAutoSignIn is YES, you try auto sign in BOOL isAutoSignIn = [HIVEAuthV4 isAutoSignIn]; if (isAutoSignIn) { // Try HIVE SDK auto login [HIVEAuthV4 signIn:kHIVEProviderTypeAUTO handler:^(HIVEResultAPI *result, HIVEPlayerInfo *playerInfo) { // // do something... }]; } else { // Try login by APPLE GameCenter account [HIVEAuthV4 signIn:kHIVEProviderTypeAPPLE handler:^(HIVEResultAPI *result, HIVEPlayerInfo *playerInfo) { Loggerd(@"HIVEAuthV4.signIn:handler:\nresult = %@\nplayerInfo = %@", result, playerInfo); if (!result.isSuccess) { return; } }]; } |
Explicit Login
Explicit Login means a process that user chooses an IdP to proceed with authentication. If a player failed to execute both Automatic Login and Implicit Login, implement the game to make the player go to the game title screen and execute Explicit Login when tapping the title.
Explicit Login is composed of the UI provided by HIVE SDK or the UI customized in games with the IdP lists returned after initializing HIVE SDK used in authentication. If you customize the UI, see Advanced > Customizing Explicit Login UI.
HIVE Platform controls and provides IdP lists in accordance with the policy of each country. For example, Google Play Games, Facebook, and Guest Login are not available in China.
An example screen of Explicit Login
IdP selection UI provided by HIVE SDK
When implementing the function with the UI provided by HIVE SDK
To implement Explicit Login with the UI provided by HIVE SDK, you can display the IdP list UI by calling showSignIn()
method.
API Reference: hive.AuthV4.showSignIn
1 2 3 4 5 6 7 8 9 10 |
// HIVE SDK AuthV4 auth UI callback handler public void onAuthV4ShowSignIn(ResultAPI result, AuthV4.PlayerInfo playerInfo) { if (result.isSuccess() == true) { // Authorization success // playerInfo : auth user info } } // Request HIVE SDK AuthV4 auth UI AuthV4.showSignIn(onAuthV4ShowSignIn); |
API Reference: AuthV4::showSignIn
1 2 3 4 5 6 7 8 9 10 11 |
// Request HIVE SDK AuthV4 auth UI AuthV4::showSignIn([=](ResultAPI const & result, PlayerInfo const & playerInfo) { // Result callback if (result.isSuccess()) { // Authorization success cout<<"PlayerName : " << playerInfo.playerName << endl; cout<<"PlayerId : " << playerInfo.playerId << endl; } else { // TODO : ErrorHandling } }); |
API Reference: com.hive.AuthV4.showSignIn
1 2 3 4 5 6 7 8 9 10 |
// HIVE SDK AuthV4 Auth UI callback handler AuthV4.showSignIn(new AuthV4.AuthV4SignInListener() { @Override public void onAuthV4SignIn(ResultAPI result, AuthV4.PlayerInfo playerInfo) { if (result.isSuccess()) { // Authorization success // playerInfo: Auth user info } } }); |
API Reference: HIVEAuthV4:showSignIn
1 2 3 4 5 6 7 8 9 |
// Request HIVE SDK Auth UI [HIVEAuthV4 showSignIn:^(HIVEResultAPI *result, HIVEPlayerInfo *playerInfo) { Loggerd(@"HIVEAuthV4.showSignIn:\nresult = %@\nplayerInfo = %@", result, playerInfo); if (!result.isSuccess) { return; } }]; |
Guest Login
HIVE supports Guest Login to allow users to use the game as a guest without selecting an IdP. You can implement this function for user to choose guest from the Explicit Login UI provided by HIVE SDK, or from the customized UI by game.
Make sure to comply with the following policy when logging in as a guest.
Guest Login Policy
-
- Build a game available for both guest users and HIVE members equally.
Most features of HIVE platform are available for guest users. So, implement your games the same for both guest users and IdP-connected users. For example, guest users are also able to purchase items and pay in the game. - Do not allow guest users to sign out.
If a user logs in as a guest and then logs out, the user can no longer sign in with the same PlayerID. Therefore, do not provide a logout button to prevent users from signing out when their state is the guest. - Guest Login Policy with Chinese IP.
If users access the game with Chinese IP, only authorized members can charge game money or purchase items (started from May 1, 2017). Therefore, IdP lists available with Chinese IP do not include Guest Login.
- Build a game available for both guest users and HIVE members equally.
Implement signIn()
method with the parameter, ProviderType.GUEST
to execute Guest Login.
Followings are sample codes to execute Guest Login.
API Reference: hive.AuthV4.signIn
1 2 3 4 5 6 7 8 9 10 |
// HIVE SDK AuthV4 Auth callback handler public void onAuthV4SignIn(ResultAPI result, AuthV4.PlayerInfo playerInfo) { if (result.isSuccess() == true) { // Authorization success // playerInfo : Auth user info. } } // GUEST 로그인 AuthV4.signIn(AuthV4.ProviderType.GUEST, onAuthV4SignIn); |
API Reference: Auth4::signIn
1 2 3 4 5 6 7 8 9 10 |
AuthV4::signIn(ProviderType::GUEST, [=](ResultAPI const & result, PlayerInfo const & playerInfo) { // Result callback if (result.isSuccess()) { // Authorization success cout<<"PlayerName : " << playerInfo.playerName << endl; cout<<"PlayerId : " << playerInfo.playerId << endl; } else { // TODO : ErrorHandling } }); |
API Reference: com.hive.Auth4.signIn
1 2 3 4 5 6 7 8 9 10 11 |
AuthV4.ProviderType providerType = AuthV4.ProviderType.GUEST; AuthV4.signIn(providerType, new AuthV4.AuthV4SignInListener() { @Override public void onAuthV4SignIn(ResultAPI result, AuthV4.PlayerInfo playerInfo) { if (result.isSuccess()) { // Authorization success // playerInfo: Auth user info. } } }); |
API Reference: HIVEAuth4:signIn
1 2 3 4 5 6 7 8 9 |
// HIVE SDK login (signIn) [HIVEAuthV4 signIn:kHIVEProviderTypeGUEST handler:^(HIVEResultAPI *result, HIVEPlayerInfo *playerInfo) { Loggerd(@"HIVEAuthV4.signIn:handler:\nresult = %@\nplayerInfo = %@", result, playerInfo); if (!result.isSuccess) { return; } }]; |
Verifying Authentication Token Key
Game server can validate the authentication token key by using the returned token, playerId, and DID information after successful login. HIVE Authentication allows multi-device logins and duplicate connections. Therefore, if the game does not allow duplicate access, you must manage the token key that has been verified or implement the function by managing the session key of the game itself using the token key.
Implement the function by referring to HIVE Server API > Verifying Authentication v4 Token.
Detecting Changes in IdP Account in the Background
Users can change their Apple Game Center or Google Play game accounts through device settings while playing the game. If you need to check whether the IdP account is matched with the account connected with the current PlayerID, implement setProviderChangedListener()
after initializing HIVE SDK. If you implement the API, user can receive an event which notifies the changes in IdP account linked on the user device when game resumes.
iOS works when the account in Apple Game Center is changed, and Android works when the account in Google Play Games is changed. And The response will be delivered only if the currently logged in PlayerID is connected with the relevant IdP. If you receive the change event in IdP account, configure the UI which allows the user to choose whether to use the IdP account logged in on the device. If the user selects the IdP account logged in on the device, call signOut
to sign out and proceed with Implicit Login.
Followings are sample codes to receive events that IdP account setting on device is changed when the player resumes the game.
API Reference: hive.AuthV4.setProviderChangedListener
1 2 3 4 5 6 7 8 9 |
// Change Provider user information authenticated to device Verification callback handler public void onAuthV4SetProviderChangedListener(ResultAPI result, AuthV4.ProviderInfo providerInfo) { if (providerInfo != null && providerInfo.providerType == AuthV4.ProviderType.APPLE) { // Change GameCenter user info } } // Request verification of changes to Provider user information that has been authenticated to the device AuthV4.setProviderChangedListener(onAuthV4SetProviderChangedListener); |
API Reference: AuthV4::setProviderChangedListener
1 2 3 4 5 6 7 8 9 10 11 |
// HIVE SDK AuthV4 Request verification of changed Provider user information AuthV4::setProviderChangedListener([=](ResultAPI const & result, ProviderInfo const & providerInfo) { // Result Callback if (result.isSuccess()) { if (providerInfo.providerType == ProviderType::GOOGLE) { // Change Google Play Game Service account } } else { // TODO : Error Handling } }); |
API Reference: com.hive.AuthV4.setProviderChangedListener
1 2 3 4 5 6 7 8 9 10 11 |
AuthV4.setProviderChangedListener(new AuthV4.AuthV4CheckProviderListener() { @Override public void onDeviceProviderInfo(ResultAPI result, ProviderInfo providerInfo) { if (result.isSuccess()) { if (providerInfo != null && providerInfo.providerType == AuthV4.ProviderType.GOOGLE) { //Change Google Play Game Service account } } } }); |
API Reference: HIVEAuthV4:setProviderChangedListener
1 2 3 4 5 6 7 8 9 |
// 기기에 인증되어 있는 Provider 사용자 정보 확인 요청 [HIVEAuthV4 setProviderChangedListener:^(HIVEResultAPI *result, HIVEProviderInfo *providerInfo) { Loggerd(@"HIVEAuthV4.setProviderChangedListener:\nresult = %@\nproviderInfo = %@", result, providerInfo); if (providerInfo && providerInfo.providerType == kHIVEProviderTypeAPPLE) { // Change GameCenter account } }]; |
Logout
If HIVE login is performed, PlayerID and authentication token key are already issued. Logout is responsible for initializing the PlayerID and the token key. If logout is completed by implementing signOut()
, move to the game title and execute the Explicit Login when user taps the title.
Followings are sample codes to implement sign-out.
API Reference: hive.AuthV4.signOut
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
// HIVE logout result callback handler // HIVE SDK result callback handler public void onAuthV4SignOut(ResultAPI result) { Logger.log("AuthV4TestView.onAuthV4SignOut() Callback\nresult = " + result.toString() + "\n"); if (result.isSuccess() != true) { // Fail logout return; } } // Request HIVE SDK logout AuthV4.signOut (onAuthV4SignOut); |
API Reference: AuthV4::signOut
1 2 3 4 5 6 7 |
AuthV4::signOut([=](ResultAPI result) { // 결과 콜백 cout<<"AuthV4::signOut() Callback"<<endl; cout<<"result = "<<result.toString()<<endl; } ); |
API Reference: com.hive.AuthV4.signOut
1 2 3 4 5 |
AuthV4.signOut(new AuthV4.AuthV4SignOutListener() { @Override public void onAuthV4SignOut(ResultAPI result) { } }); |
API Reference: HIVEAuthV4:signOut
1 2 3 4 5 6 7 8 |
[HIVEAuthV4 signOut:^(HIVEResultAPI *result) { Loggerd(@"HIVEAuthV4.signOut:\nresult = %@", result); if (!result.isSuccess) { return; } }]; |
Notification phrases for Game Center Sign-in Disabled
Language | Phrase |
---|---|
Korean | Apple Game Center 로그인이 취소되었습니다. Game Center 계정과 연동하려면 [설정 > Game Center]에서 로그인한 후 다시 시도해주세요. |
English | Your login to the Game Center has been canceled. Log in at [Settings > Game Center] to sync to the Game Center Account and try again. |
Japanese | Apple Game Center ログインがキャンセルされました。 Game Center アカウントと連動するには [設定 > Game Center] にログインした後、再度お試しください。 |
Chinese (Simplified) | Apple Game Center已退出登录。 若想与Game Center账号同步,请在设备[设置 > Game Center]中重新登录后再试。 |
Chinese (Traditional) | 登入Apple Game Center已取消。 若想連動Game Center帳號,請至[設定 > Game Center]登入後,再試一次。 |
French | Ta connexion au Game Center a été annulée. Connecte-toi dans [Réglages > Game Center] pour synchroniser ton compte Game Center et essaie de nouveau. |
German | Das Einloggen ins Apple Game Center wurde abgebrochen. Die Synchronisation mit dem Game Center-Konto läuft über [Einstellungen > Game Center]. Logge dich ein und versuche es erneut. |
Russian | Ваш авторизация в Game Center была отменена. Авторизуйтесь в Game Center через [Настройки > Game Center] и повторите попытку. |
Spanish | Tu Inicio de Sesión en Game Center ha sido cancelado. Inicia Sesión en [Configuración > Game Center] para sincronizar a la Cuenta de Game Center, e inténtalo de nuevo. |
Portuguese | O seu login no Game Center foi cancelado. Faça o login em [Configurações > Game Center] para sincronizar com a Conta do Game Center e tente novamente. |
Indonesian | Login ke Apple Game Center telah dibatalkan. Hubungkan akun Game Center dengan login di [Pengaturan > Game Center] dan coba lagi. |
Malay | Log masuk ke Game Center anda telah dibatalkan. Log masuk di [Tetapan > Game Center] untuk disegerakkan ke Akaun Game Center dan cuba lagi. |
Vietnamese | Đã hủy bỏ đăng nhập vào Apple Game Center. Đăng nhập tại [Cài đặt > Game Center] để đồng bộ với tài khoản Game Center và thử lại. |
Thai | การล็อกอินเข้า Game Center ของคุณถูกยกเลิก ล็อกอินที่ [การตั้งค่า > Game Center] เพื่อเชื่อมต่อบัญชี Game Center และโปรดลองอีกครั้ง |
Italian | L’accesso all’Apple Game Center è stato annullato. Fai log-in su [Impostazioni > Game Center] per sincronizzare il tuo account con il Game Center e riprova. |
Turkish | Apple Oyun Merkezine girişiniz iptal edilmiştir. Oyun Merkezi Hesabına ulaşmak için [Ayarlar > Oyun Merkezi]’nden giriş yapın ve tekrar deneyin. |
Arabic | تم إلغاء تسجيل الدخول إلى مركز الألعاب. سجل الدخول إلى [الإعدادات > مركز الألعاب] للمزامنة مع حساب مركز الألعاب وحاول مرة أخرى. |