Skip to content

Commit 34cbd99

Browse files
Handle passkey authenticator and unknown authenticator added in future
ref DEV-3027
2 parents 53be27f + 873391a commit 34cbd99

2 files changed

Lines changed: 71 additions & 12 deletions

File tree

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,39 @@
11
package com.oursky.authgear
22

3-
import kotlinx.serialization.SerialName
3+
import kotlinx.serialization.KSerializer
44
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
510

6-
@Serializable
11+
@Serializable(with = AuthenticatorKindSerializer::class)
712
enum class AuthenticatorKind {
8-
@SerialName("primary")
913
PRIMARY,
10-
@SerialName("secondary")
11-
SECONDARY
14+
SECONDARY,
15+
UNKNOWN
16+
}
17+
18+
object AuthenticatorKindSerializer : KSerializer<AuthenticatorKind> {
19+
override val descriptor: SerialDescriptor =
20+
PrimitiveSerialDescriptor("AuthenticatorKind", PrimitiveKind.STRING)
21+
22+
override fun deserialize(decoder: Decoder): AuthenticatorKind {
23+
val value = decoder.decodeString()
24+
return when (value) {
25+
"primary" -> AuthenticatorKind.PRIMARY
26+
"secondary" -> AuthenticatorKind.SECONDARY
27+
else -> AuthenticatorKind.UNKNOWN
28+
}
29+
}
30+
31+
override fun serialize(encoder: Encoder, value: AuthenticatorKind) {
32+
val stringValue = when (value) {
33+
AuthenticatorKind.PRIMARY -> "primary"
34+
AuthenticatorKind.SECONDARY -> "secondary"
35+
AuthenticatorKind.UNKNOWN -> "unknown"
36+
}
37+
encoder.encodeString(stringValue)
38+
}
1239
}
Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,48 @@
11
package com.oursky.authgear
22

3-
import kotlinx.serialization.SerialName
3+
import kotlinx.serialization.KSerializer
44
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
510

6-
@Serializable
11+
@Serializable(with = AuthenticatorTypeSerializer::class)
712
enum class AuthenticatorType {
8-
@SerialName("password")
913
PASSWORD,
10-
@SerialName("oob_otp_email")
1114
OOB_OTP_EMAIL,
12-
@SerialName("oob_otp_sms")
1315
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+
}
1648
}

0 commit comments

Comments
 (0)