Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 32 additions & 5 deletions sdk/src/main/java/com/oursky/authgear/AuthenticatorKind.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,39 @@
package com.oursky.authgear

import kotlinx.serialization.SerialName
import kotlinx.serialization.KSerializer
import kotlinx.serialization.Serializable
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder
import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor
import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.descriptors.PrimitiveKind

@Serializable
@Serializable(with = AuthenticatorKindSerializer::class)
enum class AuthenticatorKind {
@SerialName("primary")
PRIMARY,
@SerialName("secondary")
SECONDARY
SECONDARY,
UNKNOWN
}

object AuthenticatorKindSerializer : KSerializer<AuthenticatorKind> {
override val descriptor: SerialDescriptor =
PrimitiveSerialDescriptor("AuthenticatorKind", PrimitiveKind.STRING)

override fun deserialize(decoder: Decoder): AuthenticatorKind {
val value = decoder.decodeString()
return when (value) {
"primary" -> AuthenticatorKind.PRIMARY
"secondary" -> AuthenticatorKind.SECONDARY
else -> AuthenticatorKind.UNKNOWN
}
}

override fun serialize(encoder: Encoder, value: AuthenticatorKind) {
val stringValue = when (value) {
AuthenticatorKind.PRIMARY -> "primary"
AuthenticatorKind.SECONDARY -> "secondary"
AuthenticatorKind.UNKNOWN -> "unknown"
}
encoder.encodeString(stringValue)
}
}
46 changes: 39 additions & 7 deletions sdk/src/main/java/com/oursky/authgear/AuthenticatorType.kt
Original file line number Diff line number Diff line change
@@ -1,16 +1,48 @@
package com.oursky.authgear

import kotlinx.serialization.SerialName
import kotlinx.serialization.KSerializer
import kotlinx.serialization.Serializable
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder
import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor
import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.descriptors.PrimitiveKind

@Serializable
@Serializable(with = AuthenticatorTypeSerializer::class)
enum class AuthenticatorType {
@SerialName("password")
PASSWORD,
@SerialName("oob_otp_email")
OOB_OTP_EMAIL,
@SerialName("oob_otp_sms")
OOB_OTP_SMS,
@SerialName("totp")
TOTP
TOTP,
PASSKEY,
UNKNOWN
}

object AuthenticatorTypeSerializer : KSerializer<AuthenticatorType> {
override val descriptor: SerialDescriptor =
PrimitiveSerialDescriptor("AuthenticatorType", PrimitiveKind.STRING)

override fun deserialize(decoder: Decoder): AuthenticatorType {
val value = decoder.decodeString()
return when (value) {
"password" -> AuthenticatorType.PASSWORD
"oob_otp_email" -> AuthenticatorType.OOB_OTP_EMAIL
"oob_otp_sms" -> AuthenticatorType.OOB_OTP_SMS
"totp" -> AuthenticatorType.TOTP
"passkey" -> AuthenticatorType.PASSKEY
else -> AuthenticatorType.UNKNOWN
}
}

override fun serialize(encoder: Encoder, value: AuthenticatorType) {
val stringValue = when (value) {
AuthenticatorType.PASSWORD -> "password"
AuthenticatorType.OOB_OTP_EMAIL -> "oob_otp_email"
AuthenticatorType.OOB_OTP_SMS -> "oob_otp_sms"
AuthenticatorType.TOTP -> "totp"
AuthenticatorType.PASSKEY -> "passkey"
AuthenticatorType.UNKNOWN -> "unknown"
}
encoder.encodeString(stringValue)
}
}