SDK

Kotlin SDK

authon-kotlinAuthonClient, Custom Tab OAuth, EncryptedSharedPreferences 토큰 저장소, Jetpack Compose 헬퍼를 제공하는 Android SDK입니다.

설치

build.gradle.kts
dependencies {
    implementation("dev.authon:sdk:0.1.0")
}

초기화

Authon.kt
import dev.authon.sdk.AuthonClient

val authon = AuthonClient(
    publishableKey = "pk_live_...",
    context = applicationContext,
)

OAuth 로그인

LoginActivity.kt
import androidx.lifecycle.lifecycleScope
import dev.authon.sdk.OAuthProvider
import kotlinx.coroutines.launch

lifecycleScope.launch {
    val user = authon.signInWithOAuth(OAuthProvider.GOOGLE, activity)
    val authonAccessToken = authon.getToken()

    // If your app also has its own backend session, exchange authonAccessToken here.
}

Jetpack Compose

MainScreen.kt
import androidx.compose.runtime.Composable
import androidx.compose.material3.Button
import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.Text
import androidx.compose.foundation.layout.Column
import dev.authon.sdk.OAuthProvider
import dev.authon.sdk.compose.rememberAuthonState

@Composable
fun MainScreen() {
    val auth = rememberAuthonState(publishableKey = "pk_live_...")

    when {
        auth.isLoading -> CircularProgressIndicator()
        auth.isSignedIn -> {
            Column {
                Text("Welcome, ${auth.user?.displayName}")
                Button(onClick = { auth.signOut() }) {
                    Text("Sign out")
                }
            }
        }
        else -> {
            Button(onClick = { auth.signInWithOAuth(OAuthProvider.GOOGLE) }) {
                Text("Sign in with Google")
            }
        }
    }
}
중요한 주의사항
  • 네이티브 Android SDK는 브라우저 세션을 내부에서 처리합니다. 이 SDK를 직접 쓸 때는 Expo / React Native용 `returnTo` 브리지 플로우가 필요하지 않습니다.
  • 앱이 자체 백엔드 세션도 운영한다면 로그인 직후 `authon.getToken()`을 백엔드에 전달해 자체 세션을 발급받으세요.
  • Expo나 React Native 앱이라면 Kotlin 플로우가 아니라 React Native SDK 가이드를 따라야 합니다.
Authon — 범용 인증 플랫폼