Skip to main content

Android SDK V2 Authentication

V2 Android supports two usage styles:

  1. OegSdk for drop-in UI and legacy-style integration
  2. OEGAuth for custom UI and direct auth APIs

Option A: Drop-in login UI with OegSdk

This is the path used by the Android sample app.

Kotlin
OegSdk.showLogin(object : AuthenticationCallBack {
override fun onLoginResult(result: WorkResult<AuthenticationInfo>, provider: String?) {
if (result.isSuccess()) {
println("Login success: ${result.data?.uuid}")
} else {
println(result.error?.message)
}
}

override fun onRegisterResult(result: WorkResult<AuthenticationInfo>) = Unit

override fun onChangePassResult(result: WorkResult<Boolean>) = Unit
})
Java
OegSdk.INSTANCE.showLogin(new AuthenticationCallBack() {
@Override
public void onLoginResult(WorkResult<AuthenticationInfo> result, String provider) {
if (result.isSuccess()) {
System.out.println("Login success: " + result.data().getUuid());
} else {
System.out.println(result.error().getMessage());
}
}

@Override
public void onRegisterResult(WorkResult<AuthenticationInfo> result) {}

@Override
public void onChangePassResult(WorkResult<Boolean> result) {}
});

After login:

Kotlin
val authInfo = OegSdk.getAuthenticationInfo()
val isLoggedIn = OegSdk.isLoggedIn()
Java
AuthenticationInfo authInfo = OegSdk.INSTANCE.getAuthenticationInfo();
boolean isLoggedIn = OegSdk.INSTANCE.isLoggedIn();

Logout:

Kotlin
OegSdk.logout()
Java
OegSdk.INSTANCE.logout();

Option B: Direct API with OEGAuth

Initialize with the builder first, then call the facade methods directly:

Kotlin
OEGAuth.login("username", "password") { result ->
when (result) {
is AuthResult.Success -> {
println("Token: ${result.user.token}")
}
is AuthResult.Error -> {
println("Error: ${result.message}")
}
}
}
Java
OEGAuth.INSTANCE.login("username", "password", result -> {
if (result instanceof AuthResult.Success) {
System.out.println("Token: " + ((AuthResult.Success) result).getUser().getToken());
} else if (result instanceof AuthResult.Error) {
System.out.println("Error: " + ((AuthResult.Error) result).getMessage());
}
});

Guest login:

Kotlin
OEGAuth.playNow { result -> /* ... */ }
Java
OEGAuth.INSTANCE.playNow(result -> { /* ... */ });

Other commonly used methods:

  • OEGAuth.register(...)
  • OEGAuth.socialLogin(...)
  • OEGAuth.fetchUserInfo(...)
  • OEGAuth.updateProfile(...)
  • OEGAuth.changePassword(...)
  • OEGAuth.forgotPassword(...)

Social login notes

Google

V2 uses Credential Manager with a web client ID configured in oeg_config.json (sns.google_web_client_id). No google-services.json required.

Dependencies (already in SDK):

  • androidx.credentials:credentials
  • androidx.credentials:credentials-play-services-auth
  • com.google.android.libraries.identity.googleid

Facebook

Requires:

  • facebook_app_id
  • facebook_client_token
  • fb_login_protocol_scheme
  • The Facebook manifest entries shown on the installation page

TikTok

See the dedicated TikTok Login guide for full setup instructions including TikTok Developer Portal configuration, SDK dependency, manifest setup, and how the auth flow works.

Session state

For custom integrations, these fields are available from OEGAuth:

  • OEGAuth.currentUser
  • OEGAuth.isLoggedIn
  • OEGAuth.token

User data

After a successful login, AuthResult.Success contains an AuthUser object. You can also access it anytime via OEGAuth.getCurrentUser().

Kotlin
val user = OEGAuth.getCurrentUser()

// Identity
val userId = user?.userId // String — numeric user ID from OEG platform
val uuid = user?.uuid // String — unique UUID, stable across sessions
val username = user?.username // String? — null for guest accounts
val token = user?.token // String — JWT bearer token

// Login method — useful for analytics/tracking
val loginType = user?.loginType // LoginType enum (see below)

// Profile
val displayName = user?.displayName
val email = user?.email
val phone = user?.phone
val avatar = user?.avatar

// Account flags
val isGuest = user?.isPlayNow // true for Play Now / guest accounts
Java
AuthUser user = OEGAuth.INSTANCE.getCurrentUser();
if (user != null) {
// Identity
String userId = user.getUserId(); // numeric user ID from OEG platform
String uuid = user.getUuid(); // unique UUID, stable across sessions
String username = user.getUsername(); // null for guest accounts
String token = user.getToken(); // JWT bearer token

// Login method
LoginType loginType = user.getLoginType();

// Profile
String displayName = user.getDisplayName();
String email = user.getEmail();
String phone = user.getPhone();
String avatar = user.getAvatar();

// Account flags
boolean isGuest = user.isPlayNow(); // true for Play Now / guest accounts
}

LoginType

Kotlin
when (user?.loginType) {
LoginType.PASSWORD -> // username + password
LoginType.PLAY_NOW -> // anonymous guest
LoginType.GOOGLE -> // Google Sign-In
LoginType.FACEBOOK -> // Facebook Login
LoginType.TIKTOK -> // TikTok Login
LoginType.APPLE -> // Apple Sign-In (iOS only)
LoginType.UNKNOWN -> // restored from storage — no fresh login this session
null -> // not logged in
}
Java
if (user != null) {
switch (user.getLoginType()) {
case PASSWORD: /* username + password */ break;
case PLAY_NOW: /* anonymous guest */ break;
case GOOGLE: /* Google Sign-In */ break;
case FACEBOOK: /* Facebook Login */ break;
case TIKTOK: /* TikTok Login */ break;
case APPLE: /* Apple Sign-In (iOS only) */ break;
case UNKNOWN: /* restored from storage — no fresh login this session */ break;
}
}

Device info

Kotlin
val device = OEGAuth.getDeviceInfo()

val osId = device.osId // 1 = Android
val deviceId = device.deviceId // persistent device identifier
val sdkId = device.sdkId
val packageName = device.packageName
val gameVersion = device.gameVersion
val gameId = device.gameId
Java
DeviceInfo device = OEGAuth.INSTANCE.getDeviceInfo();

int osId = device.getOsId(); // 1 = Android
String deviceId = device.getDeviceId(); // persistent device identifier
String sdkId = device.getSdkId();
String packageName = device.getPackageName();
String gameVersion = device.getGameVersion();
int gameId = device.getGameId();

Set Game Role

After the player enters the game and selects a server/character, call setGameRole() to provide role context for analytics tracking:

Kotlin
import vn.oeg.sdk.v2.core.auth.OEGAuthCore

OEGAuthCore.setGameRole(
serverId = "server_01",
serverName = "Server 1", // optional
roleId = "character_123",
roleName = "DragonSlayer", // optional
level = 50 // optional
)
Java
import vn.oeg.sdk.v2.core.auth.OEGAuthCore;

// serverId, serverName (null = omit), roleId, roleName (null = omit), level (0 = default)
OEGAuthCore.INSTANCE.setGameRole("server_01", "Server 1", "character_123", "DragonSlayer", 50);

When to call:

  • After successful login when the player enters the game
  • When the player switches servers or characters
  • After character creation

What it does:

  • Enriches analytics events (especially sdk_recharge IAP events) with player context
  • Provides server and character information for tracking
  • Automatically cleared on logout

Parameters:

ParameterTypeRequiredDescription
serverIdStringYesGame server identifier
serverNameStringNoHuman-readable server name
roleIdStringYesCharacter/role identifier
roleNameStringNoCharacter/role display name
levelIntNoCharacter level

Example with minimal data:

Kotlin
OEGAuthCore.setGameRole(
serverId = "s1",
roleId = "char_456"
)
Java
OEGAuthCore.INSTANCE.setGameRole("s1", null, "char_456", null, 0);

Note: This data is stored in-memory only and is automatically cleared when the user logs out. If not set, analytics events will use fallback data from IAP flows when available.

Logout

Kotlin
OEGAuth.logout()
Java
OEGAuth.INSTANCE.logout();

This clears the current auth session, social state, and game role data through the v2 auth stack.

An optional callback fires immediately after local state is cleared (before the fire-and-forget API call completes):

Kotlin
OEGAuth.logout { success ->
// success is always true — fires after local session is cleared
// Navigate to your game's login screen here if needed
}
Java
OEGAuth.INSTANCE.logout(success -> {
// success is always true — fires after local session is cleared
return null;
});

Bắt sự kiện Logout tự động

Khác với iOS (dùng NotificationCenter), Android không phát broadcast khi logout xảy ra. Thay vào đó, SDK xử lý từng tình huống như sau:

Nguyên nhânSDK xử lý thế nàoGame cần làm gì
User bấm nút Đăng xuất trong DashboardSDK clear session, đóng DashboardKhông cần — UI tự đóng
Session hết hạn / token lỗi (401)SDK clear session, tự mở lại OEGLoginActivityKhông cần — SDK điều hướng tự động
Bảo trì kick outSDK clear session, hiển thị popup bảo trìDùng onMaintenanceKickOut nếu cần lưu game state trước khi bị văng

Nếu game dùng Option B (Direct API) và cần biết khi nào session hết hạn, hãy lắng nghe trạng thái đăng nhập sau khi OEGLoginActivity trả về:

Kotlin
// Kiểm tra sau khi SDK login screen đóng lại
val isLoggedIn = OEGAuth.currentUser != null
if (!isLoggedIn) {
// User đã bị logout — điều hướng về màn hình chính của game
}

Lưu ý: Nếu game dùng Option A (Drop-in UI) với OegSdk.showLogin(), tất cả các luồng logout đều được SDK quản lý hoàn toàn — game không cần xử lý thêm.

Real-time Maintenance Guard

The V2 SDK automatically monitors the server maintenance schedule and handles it without any required integration on your side:

  • Login Block: If maintenance is active, users are prevented from logging in and are shown an alert.
  • In-Game Countdown: If a maintenance window approaches during an active gameplay session, a non-intrusive countdown banner overlays the screen.
  • Automated Kick Out: When the countdown completes, the SDK safely logs the user out and displays the maintenance popup.
  • Whitelist Bypass: If a user account is marked as a tester (whitelisted) in the Alogame CMS, the SDK will bypass all maintenance blocks completely for that account.

Advanced Maintenance Configuration

If you are using the core OEGAuth.Builder for a custom integration, you can optionally configure the polling interval or intercept the kick-out sequence:

Kotlin
OEGAuth.Builder(applicationContext)
// ... basic config ...
.maintainPollingInterval(60) // Polling interval in seconds (default 60, min 30, 0 disables polling)
.onMaintenanceKickOut { info ->
// Fired immediately before the maintenance popup is shown.
// Use this callback to save current game state.
}
.build()
Java
new OEGAuth.Builder(getApplicationContext())
// ... basic config ...
.maintainPollingInterval(60) // Polling interval in seconds (default 60, min 30, 0 disables polling)
.onMaintenanceKickOut(info -> {
// Fired immediately before the maintenance popup is shown.
// Use this callback to save current game state.
})
.build();