diff --git a/auth0/src/main/java/com/auth0/android/myaccount/MyAccountAPIClient.kt b/auth0/src/main/java/com/auth0/android/myaccount/MyAccountAPIClient.kt index 401dd0d5..dcb397dd 100644 --- a/auth0/src/main/java/com/auth0/android/myaccount/MyAccountAPIClient.kt +++ b/auth0/src/main/java/com/auth0/android/myaccount/MyAccountAPIClient.kt @@ -1,6 +1,7 @@ package com.auth0.android.myaccount import androidx.annotation.VisibleForTesting +import androidx.browser.customtabs.CustomTabsService.Result import com.auth0.android.Auth0 import com.auth0.android.Auth0Exception import com.auth0.android.NetworkErrorException @@ -14,6 +15,7 @@ import com.auth0.android.request.internal.GsonAdapter.Companion.forMap import com.auth0.android.request.internal.GsonProvider import com.auth0.android.request.internal.RequestFactory import com.auth0.android.request.internal.ResponseUtils.isNetworkError +import com.auth0.android.result.AuthenticationMethod import com.auth0.android.result.PasskeyAuthenticationMethod import com.auth0.android.result.PasskeyEnrollmentChallenge import com.auth0.android.result.PasskeyRegistrationChallenge @@ -244,7 +246,7 @@ public class MyAccountAPIClient @VisibleForTesting(otherwise = VisibleForTesting "type" to "public-key", "response" to mapOf( "clientDataJSON" to credentials.response.clientDataJSON, - "attestationObject" to credentials.response.attestationObject + "attestationObject" to credentials.response.attestationObject, ) ) @@ -264,6 +266,106 @@ public class MyAccountAPIClient @VisibleForTesting(otherwise = VisibleForTesting return request } + + /** + * Retrieves a single authentication method belonging to the user. + * + * ## Availability + * + * This feature is currently available in + * [Early Access](https://auth0.com/docs/troubleshoot/product-lifecycle/product-release-stages#early-access). + * Please reach out to Auth0 support to get it enabled for your tenant. + * + * + * ## Usage + * + * ```kotlin + * val auth0 = Auth0.getInstance("YOUR_CLIENT_ID", "YOUR_DOMAIN") + * val apiClient = MyAccountAPIClient(auth0, accessToken) + * + * + * apiClient.getAuthenticationMethod(authenticationMethodId, ) + * .start(object : Callback { + * override fun onSuccess(result: AuthenticationMethod) { + * Log.d("MyApp", "Authentication method $result") + * } + * + * override fun onFailure(error: MyAccountException) { + * Log.e("MyApp", "Failed with: ${error.message}") + * } + * }) + * ``` + * + * @param authenticationMethodId Id of the authentication method to be retrieved + * + */ + public fun getAuthenticationMethod(authenticationMethodId: String): Result { + val url = + getDomainUrlBuilder() + .addPathSegment(AUTHENTICATION_METHODS) + .addPathSegment(authenticationMethodId) + .build() + + val request = factory.get( + url.toString(), + GsonAdapter(AuthenticationMethod::class.java) + ) + .addHeader(AUTHORIZATION_KEY, "Bearer $accessToken") + + return request + } + + + /** + * Deletes an existing authentication method belonging to the user. + * + * ## Availability + * + * This feature is currently available in + * [Early Access](https://auth0.com/docs/troubleshoot/product-lifecycle/product-release-stages#early-access). + * Please reach out to Auth0 support to get it enabled for your tenant. + * + * ## Scopes Required + * `delete:me:authentication-methods:passkey` + * + * ## Usage + * + * ```kotlin + * val auth0 = Auth0.getInstance("YOUR_CLIENT_ID", "YOUR_DOMAIN") + * val apiClient = MyAccountAPIClient(auth0, accessToken) + * + * + * apiClient.deleteAuthenticationMethod(authenticationMethodId, ) + * .start(object : Callback { + * override fun onSuccess(result: Void) { + * Log.d("MyApp", "Authentication method deleted") + * } + * + * override fun onFailure(error: MyAccountException) { + * Log.e("MyApp", "Failed with: ${error.message}") + * } + * }) + * ``` + * + * @param authenticationMethodId Id of the authentication method to be deleted + * + */ + public fun deleteAuthenticationMethod( + authenticationMethodId: String + ): Request { + val url = + getDomainUrlBuilder() + .addPathSegment(AUTHENTICATION_METHODS) + .addPathSegment(authenticationMethodId) + .build() + + val request = factory.delete(url.toString(), GsonAdapter(Void::class.java)) + .addHeader(AUTHORIZATION_KEY, "Bearer $accessToken") + + return request + } + + private fun getDomainUrlBuilder(): HttpUrl.Builder { return auth0.getDomainUrl().toHttpUrl().newBuilder() .addPathSegment(ME_PATH) diff --git a/auth0/src/main/java/com/auth0/android/result/AuthenticationMethod.kt b/auth0/src/main/java/com/auth0/android/result/AuthenticationMethod.kt new file mode 100644 index 00000000..ea86d350 --- /dev/null +++ b/auth0/src/main/java/com/auth0/android/result/AuthenticationMethod.kt @@ -0,0 +1,36 @@ +package com.auth0.android.result + + +import com.google.gson.annotations.SerializedName + +/** + * An Authentication Method + */ +public data class AuthenticationMethod( + @SerializedName("created_at") + val createdAt: String, + @SerializedName("credential_backed_up") + val credentialBackedUp: Boolean?, + @SerializedName("credential_device_type") + val credentialDeviceType: String?, + @SerializedName("id") + val id: String, + @SerializedName("identity_user_id") + val identityUserId: String, + @SerializedName("key_id") + val keyId: String?, + @SerializedName("last_password_reset") + val lastPasswordReset: String, + @SerializedName("public_key") + val publicKey: String?, + @SerializedName("transports") + val transports: List?, + @SerializedName("type") + val type: String, + @SerializedName("usage") + val usage: String, + @SerializedName("user_agent") + val userAgent: String?, + @SerializedName("user_handle") + val userHandle: String? +) \ No newline at end of file