Skip to content

Commit 86a90e7

Browse files
authored
SDK-6103 Added support for My Account API. (#847)
Merging after Manual Test.
2 parents 3239d94 + 4689ff3 commit 86a90e7

File tree

12 files changed

+1465
-104
lines changed

12 files changed

+1465
-104
lines changed

EXAMPLES.md

Lines changed: 400 additions & 0 deletions
Large diffs are not rendered by default.

auth0/src/main/java/com/auth0/android/myaccount/MyAccountAPIClient.kt

Lines changed: 591 additions & 56 deletions
Large diffs are not rendered by default.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.auth0.android.myaccount
2+
3+
/**
4+
* Represents the preferred method for phone-based multi-factor authentication, either "sms" or "voice".
5+
* This is used when enrolling a new phone factor or updating an existing one.
6+
*/
7+
public enum class PhoneAuthenticationMethodType(public val value: String) {
8+
SMS("sms"),
9+
VOICE("voice")
10+
}
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
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()
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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+
@JsonAdapter(EnrollmentChallenge.Deserializer::class)
11+
public sealed class EnrollmentChallenge {
12+
public abstract val id: String?
13+
public abstract val authSession: String
14+
15+
internal class Deserializer : JsonDeserializer<EnrollmentChallenge> {
16+
override fun deserialize(
17+
json: JsonElement,
18+
typeOfT: Type,
19+
context: JsonDeserializationContext
20+
): EnrollmentChallenge? {
21+
val jsonObject = json.asJsonObject
22+
val targetClass = when {
23+
jsonObject.has("barcode_uri") -> TotpEnrollmentChallenge::class.java
24+
jsonObject.has("recovery_code") -> RecoveryCodeEnrollmentChallenge::class.java
25+
jsonObject.has("authn_params_public_key") -> PasskeyEnrollmentChallenge::class.java
26+
else -> MfaEnrollmentChallenge::class.java
27+
}
28+
return context.deserialize(jsonObject, targetClass)
29+
}
30+
}
31+
}
32+
33+
public data class MfaEnrollmentChallenge(
34+
@SerializedName("id")
35+
override val id: String,
36+
@SerializedName("auth_session")
37+
override val authSession: String
38+
) : EnrollmentChallenge()
39+
40+
public data class TotpEnrollmentChallenge(
41+
@SerializedName("id")
42+
override val id: String,
43+
@SerializedName("auth_session")
44+
override val authSession: String,
45+
@SerializedName("barcode_uri")
46+
public val barcodeUri: String,
47+
@SerializedName("manual_input_code")
48+
public val manualInputCode: String?
49+
) : EnrollmentChallenge()
50+
51+
public data class RecoveryCodeEnrollmentChallenge(
52+
@SerializedName("id")
53+
override val id: String,
54+
@SerializedName("auth_session")
55+
override val authSession: String,
56+
@SerializedName("recovery_code")
57+
public val recoveryCode: String
58+
) : EnrollmentChallenge()
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package com.auth0.android.result
2+
3+
import com.google.gson.annotations.SerializedName
4+
5+
/**
6+
* Represents the payload for an enrollment request.
7+
* This is a sealed class to handle different types of enrollment payloads.
8+
*/
9+
public sealed class EnrollmentPayload(
10+
@SerializedName("type")
11+
public open val type: String
12+
)
13+
14+
public data class PasskeyEnrollmentPayload(
15+
@SerializedName("connection")
16+
public val connection: String?,
17+
@SerializedName("identity_user_id")
18+
public val identityUserId: String?
19+
) : EnrollmentPayload("passkey")
20+
21+
public object WebAuthnPlatformEnrollmentPayload : EnrollmentPayload("webauthn-platform")
22+
23+
public object WebAuthnRoamingEnrollmentPayload : EnrollmentPayload("webauthn-roaming")
24+
25+
public object TotpEnrollmentPayload : EnrollmentPayload("totp")
26+
27+
public object PushNotificationEnrollmentPayload : EnrollmentPayload("push-notification")
28+
29+
public object RecoveryCodeEnrollmentPayload : EnrollmentPayload("recovery-code")
30+
31+
public data class EmailEnrollmentPayload(
32+
@SerializedName("email")
33+
public val email: String
34+
) : EnrollmentPayload("email")
35+
36+
public data class PhoneEnrollmentPayload(
37+
@SerializedName("phone_number")
38+
public val phoneNumber: String,
39+
@SerializedName("preferred_authentication_method")
40+
public val preferredAuthenticationMethod: String
41+
) : EnrollmentPayload("phone")
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.auth0.android.result
2+
3+
import com.google.gson.annotations.SerializedName
4+
5+
public data class Factor(
6+
@SerializedName("type")
7+
public val type: String,
8+
@SerializedName("usage")
9+
public val usage: List<String>?
10+
)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.auth0.android.result
2+
3+
import com.google.gson.annotations.SerializedName
4+
5+
/**
6+
* A wrapper class for the list of factors returned by the API.
7+
*/
8+
public data class Factors(
9+
@SerializedName("factors")
10+
public val factors: List<Factor>
11+
)

auth0/src/main/java/com/auth0/android/result/PasskeyAuthenticationMethod.kt

Lines changed: 0 additions & 32 deletions
This file was deleted.
Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
package com.auth0.android.result
22

3-
import com.google.gson.annotations.SerializedName
4-
53
/**
6-
* Represents the challenge data required for enrolling a passkey.
4+
* A passkey enrollment challenge, combining the authentication method ID from the response headers
5+
* with the challenge details from the response body.
76
*/
87
public data class PasskeyEnrollmentChallenge(
9-
val authenticationMethodId: String,
10-
@SerializedName("auth_session")
11-
val authSession: String,
12-
@SerializedName("authn_params_public_key")
13-
val authParamsPublicKey: AuthnParamsPublicKey
14-
)
8+
public val authenticationMethodId: String,
9+
public val authSession: String,
10+
public val authParamsPublicKey: AuthnParamsPublicKey
11+
)

0 commit comments

Comments
 (0)