Kotlin Client
Universal Kotlin client for ezAuth. Uses OkHttp, kotlinx.serialization, and Kotlin coroutines. JVM 17+ and Android.
Installation
Gradle (Kotlin DSL)
dependencies {
implementation("org.ezauth:ezauth-client:0.1.0")
}
Gradle (Groovy)
dependencies {
implementation 'org.ezauth:ezauth-client:0.1.0'
}
Initialization
import org.ezauth.client.*
// Backend (secret key)
val ez = EZAuth(
baseUrl = "https://auth.example.com",
secretKey = "sk_live_...",
)
// Frontend (publishable key)
val ez = EZAuth(
baseUrl = "https://auth.example.com",
publishableKey = "pk_live_...",
)
Custom OkHttpClient
import okhttp3.OkHttpClient
import java.util.concurrent.TimeUnit
val ez = EZAuth(
baseUrl = "https://auth.example.com",
secretKey = "sk_live_...",
httpClient = OkHttpClient.Builder()
.connectTimeout(10, TimeUnit.SECONDS)
.readTimeout(30, TimeUnit.SECONDS)
.build(),
)
Error Handling
try {
ez.users.get("nonexistent")
} catch (e: EZAuthError) {
println(e.message) // "User not found"
println(e.status) // 404
}
ez.auth (Publishable Key)
signUp(email, password?, redirectUrl?)
val result = ez.auth.signUp(
email = "[email protected]",
password = "s3cret",
)
signIn(email, password?, strategy?, redirectUrl?)
// Password
val session = ez.auth.signIn(
email = "[email protected]",
password = "s3cret",
)
// Magic link
ez.auth.signIn(
email = "[email protected]",
redirectUrl = "https://myapp.com/dashboard",
)
verifyCode(email, code)
val session = ez.auth.verifyCode(
email = "[email protected]",
code = "482917",
)
getSession() / signOut() / refreshToken(refreshToken)
val me = ez.auth.getSession()
ez.auth.signOut()
val newSession = ez.auth.refreshToken("rt_...")
ssoExchange(token) / signInWithOAuth(provider, redirectUrl)
val session = ez.auth.ssoExchange("sso_token")
val oauthResult = ez.auth.signInWithOAuth(
provider = "google",
redirectUrl = "https://myapp.com/callback",
)
// Open oauthResult.authorizationUrl in a browser
ez.users (Secret Key)
val list = ez.users.list(limit = 10)
val user = ez.users.create(email = "[email protected]")
val found = ez.users.get(user.id)
ez.sessions (Secret Key)
ez.sessions.revoke("session-uuid")
val token = ez.sessions.createSignInToken(userId = user.id)
ez.tables
import kotlinx.serialization.json.*
val table = ez.tables.create(
name = "contacts",
columns = listOf(
ColumnDefinition(name = "name", type = "text", required = true),
ColumnDefinition(name = "age", type = "int"),
),
)
val row = ez.tables.rows.insert(
tableId = table.id,
data = buildJsonObject {
put("name", JsonPrimitive("Alice"))
put("age", JsonPrimitive(30))
},
)
val results = ez.tables.rows.query(
tableId = table.id,
filter = buildJsonObject {
put("field", JsonPrimitive("age"))
put("op", JsonPrimitive("gte"))
put("value", JsonPrimitive(18))
},
sort = SortSpec(field = "name", dir = "asc"),
limit = 50,
)
ez.storage
val usage = ez.storage.get()
println("${usage.used_percent}% used")
Dependencies
| Library | Version |
|---|---|
| OkHttp | 4.12+ |
| kotlinx-serialization-json | 1.7+ |
| kotlinx-coroutines-core | 1.9+ |