Lightweight REST client to start and verify OTP over WhatsApp.
Repo: GitHub · Module: sdk/android · Sample: sdk/android/sample
Add the dependency:
dependencies {
implementation("com.loginwa:loginwa-otp:0.1.0")
}
Until published, import the sdk/android project as a module or publish to Maven Local.
val client = LoginWAClient(
apiKey = BuildConfig.LOGINWA_API_KEY,
baseUrl = "https://api.loginwa.com/api/v1", // optional override
enableLogging = true
)
val start = client.startOtp(
StartOtpRequest(
phone = "6281234567890",
countryCode = "62",
otpLength = 6,
messageTemplate = "OTP code {code} valid for {ttl} minutes",
meta = mapOf("user_id" to "123")
)
)
val sessionId = start.sessionId
val verify = client.verifyOtp(
VerifyOtpRequest(
sessionId = sessionId.orEmpty(),
otpCode = "123456"
)
)
if (verify.status == "verified") {
// success
}
HttpError(status, code, rawBody) for non-2xx responses.NetworkError for connectivity/timeouts.SerializationError for invalid/unexpected JSON.https://api.loginwa.com/api/v1.enableLogging=true.sdk/android/sample (Activity with phone/session/OTP form).LOGINWA_API_KEY in ~/.gradle/gradle.properties, open project in Android Studio, run module :sample.