|
1 | 1 | package com.oursky.authgear |
2 | 2 |
|
3 | | -import kotlinx.serialization.SerialName |
| 3 | +import kotlinx.serialization.KSerializer |
4 | 4 | import kotlinx.serialization.Serializable |
| 5 | +import kotlinx.serialization.encoding.Decoder |
| 6 | +import kotlinx.serialization.encoding.Encoder |
| 7 | +import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor |
| 8 | +import kotlinx.serialization.descriptors.SerialDescriptor |
| 9 | +import kotlinx.serialization.descriptors.PrimitiveKind |
5 | 10 |
|
6 | | -@Serializable |
| 11 | +@Serializable(with = AuthenticatorTypeSerializer::class) |
7 | 12 | enum class AuthenticatorType { |
8 | | - @SerialName("password") |
9 | 13 | PASSWORD, |
10 | | - @SerialName("oob_otp_email") |
11 | 14 | OOB_OTP_EMAIL, |
12 | | - @SerialName("oob_otp_sms") |
13 | 15 | OOB_OTP_SMS, |
14 | | - @SerialName("totp") |
15 | | - TOTP |
| 16 | + TOTP, |
| 17 | + PASSKEY, |
| 18 | + UNKNOWN |
| 19 | +} |
| 20 | + |
| 21 | +object AuthenticatorTypeSerializer : KSerializer<AuthenticatorType> { |
| 22 | + override val descriptor: SerialDescriptor = |
| 23 | + PrimitiveSerialDescriptor("AuthenticatorType", PrimitiveKind.STRING) |
| 24 | + |
| 25 | + override fun deserialize(decoder: Decoder): AuthenticatorType { |
| 26 | + val value = decoder.decodeString() |
| 27 | + return when (value) { |
| 28 | + "password" -> AuthenticatorType.PASSWORD |
| 29 | + "oob_otp_email" -> AuthenticatorType.OOB_OTP_EMAIL |
| 30 | + "oob_otp_sms" -> AuthenticatorType.OOB_OTP_SMS |
| 31 | + "totp" -> AuthenticatorType.TOTP |
| 32 | + "passkey" -> AuthenticatorType.PASSKEY |
| 33 | + else -> AuthenticatorType.UNKNOWN |
| 34 | + } |
| 35 | + } |
| 36 | + |
| 37 | + override fun serialize(encoder: Encoder, value: AuthenticatorType) { |
| 38 | + val stringValue = when (value) { |
| 39 | + AuthenticatorType.PASSWORD -> "password" |
| 40 | + AuthenticatorType.OOB_OTP_EMAIL -> "oob_otp_email" |
| 41 | + AuthenticatorType.OOB_OTP_SMS -> "oob_otp_sms" |
| 42 | + AuthenticatorType.TOTP -> "totp" |
| 43 | + AuthenticatorType.PASSKEY -> "passkey" |
| 44 | + AuthenticatorType.UNKNOWN -> "unknown" |
| 45 | + } |
| 46 | + encoder.encodeString(stringValue) |
| 47 | + } |
16 | 48 | } |
0 commit comments