Skip to main content

Sign in with Google Account Authentication (v1 Compatible)

  • This is a Google login web authentication method. It is compatible with the Google v1 method.
  • Available for both iOS and Android.
  • PlayNANOO SDK version 5.0.0.6 or higher is recommended. (Browser cache issue fix)
  • Minimum required version: 5.0.0.3

Call Information

Sign_in_with_Google(clientId)

Call Details

ParameterDescriptionType
clientIdOAuth Web Client IDString

Source Code

using System;
using System.Threading.Tasks;
using Google;
using PlayNANOO;

public class PlayNANOOExample : MonoBehaviour
{
Plugin plugin;
private string clientId = "웹클라이언트 ID를 입력합니다.";

void Start()
{
plugin = Plugin.GetInstance();

// Android: DeepLink 콜백 등록
Application.deepLinkActivated += OnDeepLink;

}

// Android용 DeepLink 콜백
private void OnDeepLink(string url)
{
string token = ExtractIdToken(url);
if (!string.IsNullOrEmpty(token))
{
SendTokenToServer(token);
}
else
{
Debug.LogError("[GoogleOAuth] No id_token found in deep link!");
}
}

private string ExtractIdToken(string url)
{
if (!url.Contains("#")) return null;
string fragment = url.Split('#')[1];
string[] parts = fragment.Split('&');
foreach (var p in parts)
{
if (p.StartsWith("id_token="))
return p.Substring("id_token=".Length);
}
return null;
}

//인증 진행 메소드.
public void Sign_in_with_Google()
{
plugin.AccountManagerV20240401.SignInWithGoogle(clientId);
}

//인증 완료 시 토큰 받는 메소드.
private void SendTokenToServer(string token)
{
//toten 값으로 SocialChange 또는 SocialSignIn 진행.
//SocialChange(token, Configure.PN_ACCOUNT_GOOGLE);
// or
//SocialSignIn(token, Configure.PN_ACCOUNT_GOOGLE);
}

//계정 전환 예시. SocialChange
public void SocialChange(string token, string accountType)
{
//비회원 연동 - 회원 전환 참조.
plugin.AccountManagerV20240401.SocialChange(accessToken, accountType, (status, errorCode, jsonString, values) => {

}
}

//구글 계정 등록 예시. SocialSignIn
public void SocialSignIn(string token, string accountType)
{
plugin.AccountManagerV20240401.SocialSignIn(token, accountType, (status, errorCode, jsonString, values) =>
{
if (status == Configure.PN_API_STATE_SUCCESS)
{
Debug.Log(values["access_token"].ToString());
Debug.Log(values["refresh_token"].ToString());
Debug.Log(values["uuid"].ToString());
Debug.Log(values["openID"].ToString());
Debug.Log(values["nickname"].ToString());
Debug.Log(values["linkedID"].ToString());
Debug.Log(values["linkedType"].ToString());
Debug.Log(values["country"].ToString());
Debug.Log(values["purchaseCount"].ToString());
Debug.Log(values["purchaseTotalPrice"].ToString());
Debug.Log(values["purchaseCurrencyCode"].ToString());
Debug.Log(values["purchaseVoidedCount"].ToString());
Debug.Log(values["purchaseVoidedTotalPrice"].ToString());
Debug.Log(values["purchaseVoidedCurrencyCode"].ToString());
Debug.Log(values["country"].ToString());
Debug.Log(values["timezone"].ToString());
Debug.Log(values["offset"].ToString());
Debug.Log(values["joinPeriod"].ToString());
}
else
{
if (values != null)
{
if (values["ErrorCode"].ToString() == "30007")
{
Debug.Log(values["WithdrawalKey"].ToString());
}
else if (values["ErrorCode"].ToString() == "70002")
{
Debug.Log(values["BlockKey"].ToString());
}
else
{
Debug.Log("Fail");
}
}
else
{
Debug.Log("Fail");
}
}
});
}
}

How to Call

Calling Sign_in_with_Google() will open a web page where the user can select a Google account to log in with.

After selecting an account and completing authentication, the user is automatically redirected back to the app.

The token value is received through SendTokenToServer(string token).

Use the token value to proceed with Google Account Linking's Account Registration (SocialSignIn) or Account Conversion (SocialChange).

  • If converting from a guest account to a Google account, proceed with Account Conversion.
  • If logging in with Google from the start without guest linking, proceed with Account Registration.

Platform-specific Callback Handling

Android

  • Callbacks are received via the DeepLink method.
  • Register a callback method to the Application.deepLinkActivated event.
  • If the Chrome Custom Tabs library is included, the browser opens as an in-app overlay.
  • If the library is not included, the external Chrome browser opens, and the app returns via deep link after authentication.

iOS

  • An authentication session opens within the app using ASWebAuthenticationSession.
  • Register a callback with SetGoogleAuthCallback to be called when authentication is complete.
void Start()
{
Plugin plugin = Plugin.GetInstance();

// iOS Google OAuth 콜백 등록
plugin.SetGoogleAuthCallback((result) =>
{
if (result.StartsWith("error:"))
{
Debug.LogError("[GoogleOAuth] iOS Auth Error: " + result);
return;
}

// result는 콜백 URL 전체 (예: {game_id}://#id_token=xxx&...)
// ※ mygame:// scheme은 deprecated 되었습니다. PlayNANOO 콘솔에 등록된 Game ID를 scheme으로 사용합니다.
string token = ExtractIdToken(result);
if (!string.IsNullOrEmpty(token))
{
// 토큰으로 SocialSignIn 또는 SocialChange 호출
}
});
}

private string ExtractIdToken(string url)
{
if (!url.Contains("#")) return null;
string fragment = url.Split('#')[1];
string[] parts = fragment.Split('&');
foreach (var p in parts)
{
if (p.StartsWith("id_token="))
return p.Substring("id_token=".Length);
}
return null;
}

Response

HTTP/1.1 200 OK
Content-Type: application/json;charset=UTF-8
{
"Token" : {
"AccessToken" : "String",
"RefreshToken" : "String"
},
"Player" : {
"UserUniqueID" : "String",
"OpenID" : "String",
"Nickname" : "String",
"LinkedID" : "String",
"LinkedType" : "String",
"PurchaseCount" : "Integer",
"PurchaseTotalPrice" : "Double",
"PurchaseCurrencyCode" : "String",
"PurchaseVoidedCount" : "Integer",
"PurchaseVoidedTotalPrice" : "Double",
"PurchaseVoidedCurrencyCode" : "String",
"Country" : "String",
"Timezone" : "String",
"Offset" : "Integer",
"JoinPeriod" : "Integer"
}
}

Response Details

Data KeyDescriptionType
Token.AccessTokenPlayer access tokenstring
Token.RefreshTokenPlayer refresh tokenstring
Player.UserUniqueIDPlayer unique IDstring
Player.OpenIDPlayer unique open IDstring
Player.NicknamePlayer nicknamestring
Player.LinkedIDPlayer linked IDstring
Player.LinkedTypePlayer link typestring
Player.PurchaseCountPlayer purchase countinteger
Player.PurchaseTotalPricePlayer cumulative purchase amountdouble
Player.PurchaseCurrencyCodePlayer purchase currencystring
Player.PurchaseVoidedCountPlayer refund countinteger
Player.PurchaseVoidedTotalPricePlayer cumulative refund amountdouble
Player.PurchaseVoidedCurrencyCodePlayer refund currencystring
Player.CountryPlayer country codestring
Player.TimezonePlayer country timezonestring
Player.OffsetPlayer timezone offset (based on UTC)integer
Player.JoinPeriodPlayer membership durationinteger
WithdrawalKeyWithdrawal account lookup keystring

Error Information

If player information does not exist. ErrorCode : 30000 ErrorMessage : NotFoundAccountException

If player information is being used on another device ErrorCode : 30006 ErrorMessage : DuplicatedDeviceException

If the player has requested withdrawal ErrorCode : 30007 ErrorMessage : WithDrawalException