플레이어와 로그인
재시작해도 유지되는 게스트 계정, 표시 이름, 게스트를 이메일 또는 Google 계정에 연결하는 방법을 설명합니다.
코드 주석과 API 이름은 SDK와 일치하도록 영어로 유지합니다.
게스트 로그인#
시작할 때 한 번 호출하세요. 저장된 세션을 복원(필요하면 갱신)하거나 새 게스트를 만들어, 같은 플레이어가 진행 상황을 유지하도록 합니다.
var signIn = await Majacloud.Auth.SignInAnonymouslyAsync();
if (signIn.Ok)
{
var player = signIn.Value;
Debug.Log(player.PlayerId + " " + player.DisplayName + " guest: " + player.IsGuest);
}var signed_in := await Majacloud.auth.sign_in_anonymously()
if signed_in.ok:
var player: Dictionary = signed_in.value
print(player.player_id, " ", player.display_name, " ", player.auth_type)const signIn = await mc.auth.signInAnonymously();
if (signIn.ok) {
const player = signIn.value;
console.log(player.player_id, player.display_name, player.auth_type);
}curl -X POST https://majacloud.majanite.com/v1/auth/guest -H "X-Project-ID: $PROJECT_ID" -H "X-Client-Key: $CLIENT_KEY" \
-H "Content-Type: application/json" -d '{"device_id": "install-7f2c"}'
# Before the access token expires (1 hour), rotate the session:
curl -X POST https://majacloud.majanite.com/v1/auth/refresh -H "X-Project-ID: $PROJECT_ID" -H "X-Client-Key: $CLIENT_KEY" \
-H "Content-Type: application/json" -d '{"refresh_token": "<refresh_token>"}'표시 이름#
게스트에게는 Guest 4821 같은 이름이 자동으로 부여됩니다. 플레이어가 직접 이름을 정할 수 있으며, 리더보드에는 이 이름이 표시됩니다.
var renamed = await Majacloud.Auth.SetDisplayNameAsync("Nova");
if (!renamed.Ok) Debug.Log(renamed.Error.Message); // e.g. Validation: too longvar renamed := await Majacloud.auth.set_display_name("Nova")
if not renamed.ok:
print(renamed.message) # e.g. validation: too longconst renamed = await mc.auth.setDisplayName('Nova');
if (!renamed.ok) console.log(renamed.error.message); // e.g. validation: too longcurl -X PATCH https://majacloud.majanite.com/v1/players/me -H "X-Project-ID: $PROJECT_ID" -H "X-Client-Key: $CLIENT_KEY" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" -d '{"display_name": "Nova"}'이메일 또는 Google 계정 연결#
계정을 연결하면 MAJACLOUD 서버의 보안 웹 페이지가 열리고, 플레이어는 이메일과 비밀번호 또는 Google로 로그인하거나 가입합니다. 게스트의 진행 상황(점수, 저장 데이터, 지갑)은 해당 계정으로 이전되고, 게임은 새 세션을 받습니다. 어떤 기기에서든 마찬가지입니다.
// Opens the sign-in page, waits for the player, then switches the session
var linked = await Majacloud.Auth.LinkAccountAsync(new MajacloudLinkOptions { ReturnUrl = "mygame://auth" });
if (linked.Ok) Debug.Log("Signed in as " + linked.Value.DisplayName);
// WebGL: browsers only open tabs from a click, so start first and open inside the handler
var flow = await Majacloud.Auth.StartLinkAsync(new MajacloudLinkOptions { OpenBrowser = false });
linkButton.onClick.AddListener(() => flow.Value.OpenInBrowser());
var result = await flow.Value.WaitForCompletionAsync();# Opens the sign-in page, waits for the player, then switches the session
var linked := await Majacloud.auth.link_account("mygame://auth")
if linked.ok:
print("Signed in as ", linked.value.display_name)
# Or step by step (e.g. to open the page from a button)
var started := await Majacloud.auth.start_link()
var flow: MajacloudLinkFlow = started.value
flow.open_in_browser()
var result := await flow.wait_for_completion()// Call it from a click handler: the browser only allows the new tab after a user gesture
document.querySelector('#link').addEventListener('click', async () => {
const linked = await mc.auth.linkAccount();
if (linked.ok) console.log('Signed in as ' + linked.value.display_name);
});# 1. Start (send the guest's Bearer token so its progress is merged)
curl -X POST https://majacloud.majanite.com/v1/auth/link/start -H "X-Project-ID: $PROJECT_ID" -H "X-Client-Key: $CLIENT_KEY" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" -d '{"code_challenge": "<base64url(sha256(verifier))>", "code_challenge_method": "S256"}'
# 2. Open auth_url for the player, then poll until status is "completed"
curl "https://majacloud.majanite.com/v1/auth/link/status?flow_id=<flow_id>&flow_token=<flow_token>" -H "X-Project-ID: $PROJECT_ID" -H "X-Client-Key: $CLIENT_KEY"
# 3. Exchange for the new session
curl -X POST https://majacloud.majanite.com/v1/auth/link/exchange -H "X-Project-ID: $PROJECT_ID" -H "X-Client-Key: $CLIENT_KEY" \
-H "Content-Type: application/json" -d '{"flow_id": "<flow_id>", "exchange_code": "<exchange_code>", "code_verifier": "<verifier>"}'연결 방식#
- SDK가 일회용 시크릿(PKCE)을 만들고 로그인 플로우를 시작합니다.
- 플레이어가 웹 페이지에서 절차를 마치는 동안 SDK는 플로우가 완료될 때까지 폴링합니다.
- SDK는 시크릿을 사용해 플로우를 세션으로 교환하므로, 링크가 탈취되어도 쓸모가 없습니다.
- 플로우는 15분 후 만료됩니다(페이지가 열려 있는 동안에는 연장됩니다).
게임으로 돌아가기#
반환 URL이 없으면 페이지가 플레이어에게 게임으로 돌아가라고 안내합니다. 자동으로 돌려보내려면 API 키 ▸ 플레이어 로그인 반환 URL에 사용자 지정 URL 스킴(예: mygame)을 추가하고 반환 URL로 mygame://auth를 전달하세요.
이벤트#
플레이어가 바뀌거나 로그아웃할 때, 또는 세션을 더 이상 갱신할 수 없을 때 대응합니다:
Majacloud.Auth.PlayerChanged += player => nameLabel.text = player?.DisplayName;
Majacloud.Auth.SignedOut += () => ShowTitleScreen();
Majacloud.Auth.SessionExpired += () => ShowSignIn();Majacloud.auth.player_changed.connect(func(player): $NameLabel.text = player.get("display_name", ""))
Majacloud.auth.signed_out.connect(show_title_screen)
Majacloud.auth.session_expired.connect(show_sign_in)mc.auth.on('playerChanged', (player) => render(player));
mc.auth.on('signedOut', () => showTitleScreen());
mc.auth.on('sessionExpired', () => showSignIn());로그아웃#
로그아웃하면 서버에서 세션이 취소되고 기기에서도 삭제됩니다. 다음 로그인 시 새 게스트가 생성됩니다.
await Majacloud.Auth.SignOutAsync(); // revokes the session on the server
Majacloud.Auth.ClearLocalSession(); // or only forget it on this deviceawait Majacloud.auth.sign_out() # revokes the session on the server
Majacloud.auth.clear_local_session() # or only forget it on this deviceawait mc.auth.signOut(); // revokes the session on the server
mc.auth.clearLocalSession(); // or only forget it on this devicecurl -X POST https://majacloud.majanite.com/v1/auth/logout -H "X-Project-ID: $PROJECT_ID" -H "X-Client-Key: $CLIENT_KEY" \
-H "Content-Type: application/json" -d '{"refresh_token": "<refresh_token>"}'서버에서 플레이어 조회#
시크릿 키를 사용하면 서버에서 이메일과 지갑 잔액을 포함한 모든 플레이어 정보를 조회할 수 있습니다:
// Node.js, created with secretKey
const found = await admin.server.getPlayer('player_3f9c…');
if (found.ok) console.log(found.value.player.email, found.value.player.wallets);curl https://majacloud.majanite.com/v1/players/player_3f9c… \
-H "X-Project-ID: $PROJECT_ID" -H "X-Secret-Key: $SECRET_KEY"대시보드에서#
플레이어 페이지에는 모든 플레이어가 로그인 방식, 점수, 저장 데이터, 지갑과 함께 표시됩니다. 여기서 플레이어의 이름을 바꾸거나 비활성화하고, 모든 기기에서 로그아웃시키고, 비밀번호 재설정 링크를 보내거나 삭제할 수 있습니다.