Skip to content

Added support for Passkey Management API [DO NOT MERGE] #842

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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,
)
)

Expand All @@ -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<AuthenticationMethod, MyAccountException> {
* 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<AuthenticationMethod, MyAccountException> {
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<Void, MyAccountException> {
* 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<Void, MyAccountException> {
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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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<String>?,
@SerializedName("type")
val type: String,
@SerializedName("usage")
val usage: String,
@SerializedName("user_agent")
val userAgent: String?,
@SerializedName("user_handle")
val userHandle: String?
)
Loading