1+ package com.auth0.android.result
2+
3+ import com.google.gson.JsonDeserializationContext
4+ import com.google.gson.JsonDeserializer
5+ import com.google.gson.JsonElement
6+ import com.google.gson.annotations.JsonAdapter
7+ import com.google.gson.annotations.SerializedName
8+ import java.lang.reflect.Type
9+
10+ public data class AuthenticationMethods (
11+ @SerializedName(" authentication_methods" )
12+ public val authenticationMethods : List <AuthenticationMethod >
13+ )
14+
15+ @JsonAdapter(AuthenticationMethod .Deserializer ::class )
16+ public sealed class AuthenticationMethod {
17+ public abstract val id: String
18+ public abstract val type: String
19+ public abstract val createdAt: String
20+ public abstract val usage: List <String >
21+
22+ internal class Deserializer : JsonDeserializer <AuthenticationMethod > {
23+ override fun deserialize (
24+ json : JsonElement ,
25+ typeOfT : Type ,
26+ context : JsonDeserializationContext
27+ ): AuthenticationMethod ? {
28+ val jsonObject = json.asJsonObject
29+ val type = jsonObject.get(" type" )?.asString
30+ val targetClass = when (type) {
31+ " password" -> PasswordAuthenticationMethod ::class .java
32+ " passkey" -> PasskeyAuthenticationMethod ::class .java
33+ " recovery-code" -> RecoveryCodeAuthenticationMethod ::class .java
34+ " push-notification" -> PushNotificationAuthenticationMethod ::class .java
35+ " totp" -> TotpAuthenticationMethod ::class .java
36+ " webauthn-platform" -> WebAuthnPlatformAuthenticationMethod ::class .java
37+ " webauthn-roaming" -> WebAuthnRoamingAuthenticationMethod ::class .java
38+ " phone" -> PhoneAuthenticationMethod ::class .java
39+ " email" -> EmailAuthenticationMethod ::class .java
40+ else -> null
41+ }
42+ return context.deserialize(jsonObject, targetClass)
43+ }
44+ }
45+ }
46+
47+ public data class PasswordAuthenticationMethod (
48+ @SerializedName(" id" ) override val id : String ,
49+ @SerializedName(" type" ) override val type : String ,
50+ @SerializedName(" created_at" ) override val createdAt : String ,
51+ @SerializedName(" usage" ) override val usage : List <String >,
52+ @SerializedName(" identity_user_id" )
53+ public val identityUserId : String? ,
54+ @SerializedName(" last_password_reset" )
55+ public val lastPasswordReset : String?
56+ ) : AuthenticationMethod()
57+
58+ public data class PasskeyAuthenticationMethod (
59+ @SerializedName(" id" ) override val id : String ,
60+ @SerializedName(" type" ) override val type : String ,
61+ @SerializedName(" created_at" ) override val createdAt : String ,
62+ @SerializedName(" usage" ) override val usage : List <String >,
63+ @SerializedName(" credential_backed_up" )
64+ public val credentialBackedUp : Boolean? ,
65+ @SerializedName(" credential_device_type" )
66+ public val credentialDeviceType : String? ,
67+ @SerializedName(" identity_user_id" )
68+ public val identityUserId : String? ,
69+ @SerializedName(" key_id" )
70+ public val keyId : String? ,
71+ @SerializedName(" public_key" )
72+ public val publicKey : String? ,
73+ @SerializedName(" transports" )
74+ public val transports : List <String >? ,
75+ @SerializedName(" user_agent" )
76+ public val userAgent : String? ,
77+ @SerializedName(" user_handle" )
78+ public val userHandle : String?
79+ ) : AuthenticationMethod()
80+
81+ public sealed class MfaAuthenticationMethod : AuthenticationMethod () {
82+ public abstract val confirmed: Boolean?
83+ }
84+
85+ public data class RecoveryCodeAuthenticationMethod (
86+ @SerializedName(" id" ) override val id : String ,
87+ @SerializedName(" type" ) override val type : String ,
88+ @SerializedName(" created_at" ) override val createdAt : String ,
89+ @SerializedName(" usage" ) override val usage : List <String >,
90+ @SerializedName(" confirmed" ) override val confirmed : Boolean?
91+ ) : MfaAuthenticationMethod()
92+
93+ public data class PushNotificationAuthenticationMethod (
94+ @SerializedName(" id" ) override val id : String ,
95+ @SerializedName(" type" ) override val type : String ,
96+ @SerializedName(" created_at" ) override val createdAt : String ,
97+ @SerializedName(" usage" ) override val usage : List <String >,
98+ @SerializedName(" confirmed" ) override val confirmed : Boolean? ,
99+ @SerializedName(" name" )
100+ public val name : String?
101+ ) : MfaAuthenticationMethod()
102+
103+ public data class TotpAuthenticationMethod (
104+ @SerializedName(" id" ) override val id : String ,
105+ @SerializedName(" type" ) override val type : String ,
106+ @SerializedName(" created_at" ) override val createdAt : String ,
107+ @SerializedName(" usage" ) override val usage : List <String >,
108+ @SerializedName(" confirmed" ) override val confirmed : Boolean? ,
109+ @SerializedName(" name" )
110+ public val name : String?
111+ ) : MfaAuthenticationMethod()
112+
113+ public sealed class WebAuthnAuthenticationMethod : MfaAuthenticationMethod () {
114+ public abstract val name: String?
115+ public abstract val keyId: String?
116+ public abstract val publicKey: String?
117+ }
118+
119+ public data class WebAuthnPlatformAuthenticationMethod (
120+ @SerializedName(" id" ) override val id : String ,
121+ @SerializedName(" type" ) override val type : String ,
122+ @SerializedName(" created_at" ) override val createdAt : String ,
123+ @SerializedName(" usage" ) override val usage : List <String >,
124+ @SerializedName(" confirmed" ) override val confirmed : Boolean? ,
125+ @SerializedName(" name" ) override val name : String? ,
126+ @SerializedName(" key_id" ) override val keyId : String? ,
127+ @SerializedName(" public_key" ) override val publicKey : String?
128+ ) : WebAuthnAuthenticationMethod()
129+
130+ public data class WebAuthnRoamingAuthenticationMethod (
131+ @SerializedName(" id" ) override val id : String ,
132+ @SerializedName(" type" ) override val type : String ,
133+ @SerializedName(" created_at" ) override val createdAt : String ,
134+ @SerializedName(" usage" ) override val usage : List <String >,
135+ @SerializedName(" confirmed" ) override val confirmed : Boolean? ,
136+ @SerializedName(" name" ) override val name : String? ,
137+ @SerializedName(" key_id" ) override val keyId : String? ,
138+ @SerializedName(" public_key" ) override val publicKey : String?
139+ ) : WebAuthnAuthenticationMethod()
140+
141+ public data class PhoneAuthenticationMethod (
142+ @SerializedName(" id" ) override val id : String ,
143+ @SerializedName(" type" ) override val type : String ,
144+ @SerializedName(" created_at" ) override val createdAt : String ,
145+ @SerializedName(" usage" ) override val usage : List <String >,
146+ @SerializedName(" confirmed" ) override val confirmed : Boolean? ,
147+ @SerializedName(" name" )
148+ public val name : String? ,
149+ @SerializedName(" phone_number" )
150+ public val phoneNumber : String? ,
151+ @SerializedName(" preferred_authentication_method" )
152+ public val preferredAuthenticationMethod : String?
153+ ) : MfaAuthenticationMethod()
154+
155+ public data class EmailAuthenticationMethod (
156+ @SerializedName(" id" ) override val id : String ,
157+ @SerializedName(" type" ) override val type : String ,
158+ @SerializedName(" created_at" ) override val createdAt : String ,
159+ @SerializedName(" usage" ) override val usage : List <String >,
160+ @SerializedName(" confirmed" ) override val confirmed : Boolean? ,
161+ @SerializedName(" name" )
162+ public val name : String? ,
163+ @SerializedName(" email" )
164+ public val email : String?
165+ ) : MfaAuthenticationMethod()
0 commit comments