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
400 changes: 400 additions & 0 deletions EXAMPLES.md

Large diffs are not rendered by default.

647 changes: 591 additions & 56 deletions auth0/src/main/java/com/auth0/android/myaccount/MyAccountAPIClient.kt

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.auth0.android.myaccount

/**
* Represents the preferred method for phone-based multi-factor authentication, either "sms" or "voice".
* This is used when enrolling a new phone factor or updating an existing one.
*/
public enum class PhoneAuthenticationMethodType(public val value: String) {
SMS("sms"),
VOICE("voice")
}
165 changes: 165 additions & 0 deletions auth0/src/main/java/com/auth0/android/result/AuthenticationMethod.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
package com.auth0.android.result

import com.google.gson.JsonDeserializationContext
import com.google.gson.JsonDeserializer
import com.google.gson.JsonElement
import com.google.gson.annotations.JsonAdapter
import com.google.gson.annotations.SerializedName
import java.lang.reflect.Type

public data class AuthenticationMethods(
@SerializedName("authentication_methods")
public val authenticationMethods: List<AuthenticationMethod>
)

@JsonAdapter(AuthenticationMethod.Deserializer::class)
public sealed class AuthenticationMethod {
public abstract val id: String
public abstract val type: String
public abstract val createdAt: String
public abstract val usage: List<String>

internal class Deserializer : JsonDeserializer<AuthenticationMethod> {
override fun deserialize(
json: JsonElement,
typeOfT: Type,
context: JsonDeserializationContext
): AuthenticationMethod? {
val jsonObject = json.asJsonObject
val type = jsonObject.get("type")?.asString
val targetClass = when (type) {
"password" -> PasswordAuthenticationMethod::class.java
"passkey" -> PasskeyAuthenticationMethod::class.java
"recovery-code" -> RecoveryCodeAuthenticationMethod::class.java
"push-notification" -> PushNotificationAuthenticationMethod::class.java
"totp" -> TotpAuthenticationMethod::class.java
"webauthn-platform" -> WebAuthnPlatformAuthenticationMethod::class.java
"webauthn-roaming" -> WebAuthnRoamingAuthenticationMethod::class.java
"phone" -> PhoneAuthenticationMethod::class.java
"email" -> EmailAuthenticationMethod::class.java
else -> null
}
return context.deserialize(jsonObject, targetClass)
}
}
}

public data class PasswordAuthenticationMethod(
@SerializedName("id") override val id: String,
@SerializedName("type") override val type: String,
@SerializedName("created_at") override val createdAt: String,
@SerializedName("usage") override val usage: List<String>,
@SerializedName("identity_user_id")
public val identityUserId: String?,
@SerializedName("last_password_reset")
public val lastPasswordReset: String?
) : AuthenticationMethod()

public data class PasskeyAuthenticationMethod(
@SerializedName("id") override val id: String,
@SerializedName("type") override val type: String,
@SerializedName("created_at") override val createdAt: String,
@SerializedName("usage") override val usage: List<String>,
@SerializedName("credential_backed_up")
public val credentialBackedUp: Boolean?,
@SerializedName("credential_device_type")
public val credentialDeviceType: String?,
@SerializedName("identity_user_id")
public val identityUserId: String?,
@SerializedName("key_id")
public val keyId: String?,
@SerializedName("public_key")
public val publicKey: String?,
@SerializedName("transports")
public val transports: List<String>?,
@SerializedName("user_agent")
public val userAgent: String?,
@SerializedName("user_handle")
public val userHandle: String?
) : AuthenticationMethod()

public sealed class MfaAuthenticationMethod : AuthenticationMethod() {
public abstract val confirmed: Boolean?
}

public data class RecoveryCodeAuthenticationMethod(
@SerializedName("id") override val id: String,
@SerializedName("type") override val type: String,
@SerializedName("created_at") override val createdAt: String,
@SerializedName("usage") override val usage: List<String>,
@SerializedName("confirmed") override val confirmed: Boolean?
) : MfaAuthenticationMethod()

public data class PushNotificationAuthenticationMethod(
@SerializedName("id") override val id: String,
@SerializedName("type") override val type: String,
@SerializedName("created_at") override val createdAt: String,
@SerializedName("usage") override val usage: List<String>,
@SerializedName("confirmed") override val confirmed: Boolean?,
@SerializedName("name")
public val name: String?
) : MfaAuthenticationMethod()

public data class TotpAuthenticationMethod(
@SerializedName("id") override val id: String,
@SerializedName("type") override val type: String,
@SerializedName("created_at") override val createdAt: String,
@SerializedName("usage") override val usage: List<String>,
@SerializedName("confirmed") override val confirmed: Boolean?,
@SerializedName("name")
public val name: String?
) : MfaAuthenticationMethod()

public sealed class WebAuthnAuthenticationMethod : MfaAuthenticationMethod() {
public abstract val name: String?
public abstract val keyId: String?
public abstract val publicKey: String?
}

public data class WebAuthnPlatformAuthenticationMethod(
@SerializedName("id") override val id: String,
@SerializedName("type") override val type: String,
@SerializedName("created_at") override val createdAt: String,
@SerializedName("usage") override val usage: List<String>,
@SerializedName("confirmed") override val confirmed: Boolean?,
@SerializedName("name") override val name: String?,
@SerializedName("key_id") override val keyId: String?,
@SerializedName("public_key") override val publicKey: String?
) : WebAuthnAuthenticationMethod()

public data class WebAuthnRoamingAuthenticationMethod(
@SerializedName("id") override val id: String,
@SerializedName("type") override val type: String,
@SerializedName("created_at") override val createdAt: String,
@SerializedName("usage") override val usage: List<String>,
@SerializedName("confirmed") override val confirmed: Boolean?,
@SerializedName("name") override val name: String?,
@SerializedName("key_id") override val keyId: String?,
@SerializedName("public_key") override val publicKey: String?
) : WebAuthnAuthenticationMethod()

public data class PhoneAuthenticationMethod(
@SerializedName("id") override val id: String,
@SerializedName("type") override val type: String,
@SerializedName("created_at") override val createdAt: String,
@SerializedName("usage") override val usage: List<String>,
@SerializedName("confirmed") override val confirmed: Boolean?,
@SerializedName("name")
public val name: String?,
@SerializedName("phone_number")
public val phoneNumber: String?,
@SerializedName("preferred_authentication_method")
public val preferredAuthenticationMethod: String?
) : MfaAuthenticationMethod()

public data class EmailAuthenticationMethod(
@SerializedName("id") override val id: String,
@SerializedName("type") override val type: String,
@SerializedName("created_at") override val createdAt: String,
@SerializedName("usage") override val usage: List<String>,
@SerializedName("confirmed") override val confirmed: Boolean?,
@SerializedName("name")
public val name: String?,
@SerializedName("email")
public val email: String?
) : MfaAuthenticationMethod()
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.auth0.android.result

import com.google.gson.JsonDeserializationContext
import com.google.gson.JsonDeserializer
import com.google.gson.JsonElement
import com.google.gson.annotations.JsonAdapter
import com.google.gson.annotations.SerializedName
import java.lang.reflect.Type

@JsonAdapter(EnrollmentChallenge.Deserializer::class)
public sealed class EnrollmentChallenge {
public abstract val id: String?
public abstract val authSession: String

internal class Deserializer : JsonDeserializer<EnrollmentChallenge> {
override fun deserialize(
json: JsonElement,
typeOfT: Type,
context: JsonDeserializationContext
): EnrollmentChallenge? {
val jsonObject = json.asJsonObject
val targetClass = when {
jsonObject.has("barcode_uri") -> TotpEnrollmentChallenge::class.java
jsonObject.has("recovery_code") -> RecoveryCodeEnrollmentChallenge::class.java
jsonObject.has("authn_params_public_key") -> PasskeyEnrollmentChallenge::class.java
else -> MfaEnrollmentChallenge::class.java
}
return context.deserialize(jsonObject, targetClass)
}
}
}

public data class MfaEnrollmentChallenge(
@SerializedName("id")
override val id: String,
@SerializedName("auth_session")
override val authSession: String
) : EnrollmentChallenge()

public data class TotpEnrollmentChallenge(
@SerializedName("id")
override val id: String,
@SerializedName("auth_session")
override val authSession: String,
@SerializedName("barcode_uri")
public val barcodeUri: String,
@SerializedName("manual_input_code")
public val manualInputCode: String?
) : EnrollmentChallenge()

public data class RecoveryCodeEnrollmentChallenge(
@SerializedName("id")
override val id: String,
@SerializedName("auth_session")
override val authSession: String,
@SerializedName("recovery_code")
public val recoveryCode: String
) : EnrollmentChallenge()
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.auth0.android.result

import com.google.gson.annotations.SerializedName

/**
* Represents the payload for an enrollment request.
* This is a sealed class to handle different types of enrollment payloads.
*/
public sealed class EnrollmentPayload(
@SerializedName("type")
public open val type: String
)

public data class PasskeyEnrollmentPayload(
@SerializedName("connection")
public val connection: String?,
@SerializedName("identity_user_id")
public val identityUserId: String?
) : EnrollmentPayload("passkey")

public object WebAuthnPlatformEnrollmentPayload : EnrollmentPayload("webauthn-platform")

public object WebAuthnRoamingEnrollmentPayload : EnrollmentPayload("webauthn-roaming")

public object TotpEnrollmentPayload : EnrollmentPayload("totp")

public object PushNotificationEnrollmentPayload : EnrollmentPayload("push-notification")

public object RecoveryCodeEnrollmentPayload : EnrollmentPayload("recovery-code")

public data class EmailEnrollmentPayload(
@SerializedName("email")
public val email: String
) : EnrollmentPayload("email")

public data class PhoneEnrollmentPayload(
@SerializedName("phone_number")
public val phoneNumber: String,
@SerializedName("preferred_authentication_method")
public val preferredAuthenticationMethod: String
) : EnrollmentPayload("phone")
10 changes: 10 additions & 0 deletions auth0/src/main/java/com/auth0/android/result/Factor.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.auth0.android.result

import com.google.gson.annotations.SerializedName

Copy link

Copilot AI Aug 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Factor class lacks documentation. Public data classes should have KDoc comments explaining their purpose and properties.

Suggested change
/**
* Represents a multi-factor authentication factor.
*
* @property type The type of factor (e.g., "totp", "sms", etc.).
* @property usage The usages supported by this factor (e.g., "authentication", "recovery"). May be null.
*/

Copilot uses AI. Check for mistakes.
public data class Factor(
@SerializedName("type")
public val type: String,
@SerializedName("usage")
public val usage: List<String>?
)
11 changes: 11 additions & 0 deletions auth0/src/main/java/com/auth0/android/result/Factors.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.auth0.android.result

import com.google.gson.annotations.SerializedName

/**
* A wrapper class for the list of factors returned by the API.
*/
public data class Factors(
@SerializedName("factors")
public val factors: List<Factor>
)

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
package com.auth0.android.result

import com.google.gson.annotations.SerializedName

/**
* Represents the challenge data required for enrolling a passkey.
* A passkey enrollment challenge, combining the authentication method ID from the response headers
* with the challenge details from the response body.
*/
public data class PasskeyEnrollmentChallenge(
val authenticationMethodId: String,
@SerializedName("auth_session")
val authSession: String,
@SerializedName("authn_params_public_key")
val authParamsPublicKey: AuthnParamsPublicKey
)
public val authenticationMethodId: String,
public val authSession: String,
public val authParamsPublicKey: AuthnParamsPublicKey
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.auth0.android.result

import com.google.gson.annotations.SerializedName

/**
* Represents the payload for a verification request, such as providing an OTP code.
*/
public data class VerifyOtpPayload(
@SerializedName("otp_code")
public val otpCode: String
)
Loading