Skip to content
Draft
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
10 changes: 10 additions & 0 deletions auth0/src/main/java/com/auth0/android/request/UserData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,20 @@ import com.google.gson.annotations.SerializedName
* @param phoneNumber the phone number of the user. phone number can be optional, required, or forbidden depending on the attribute configuration for the database
* @param userName the username of the user. username can be optional, required, or forbidden depending on the attribute configuration for the database
* @param name optional display name
* @param givenName the first name of the user
* @param familyName the last name of the user
* @param nickName the preferred nickname of the user
* @param picture URL pointing to the user's profile picture
* @param userMetadata additional user metadata as key-value pairs
*/
public data class UserData(
@field:SerializedName("email") val email: String? = null,
@field:SerializedName("phone_number") val phoneNumber: String? = null,
@field:SerializedName("username") val userName: String? = null,
@field:SerializedName("name") val name: String? = null,
@field:SerializedName("given_name") val givenName: String? = null,
@field:SerializedName("family_name") val familyName: String? = null,
@field:SerializedName("nickname") val nickName: String? = null,
@field:SerializedName("picture") val picture: String? = null,
@field:SerializedName("user_metadata") val userMetadata: Map<String, String>? = null,
)
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import com.auth0.android.provider.JwtTestUtils
import com.auth0.android.request.HttpMethod
import com.auth0.android.request.NetworkingClient
import com.auth0.android.request.PublicKeyCredentials
import com.auth0.android.request.UserData
import com.auth0.android.request.RequestOptions
import com.auth0.android.request.ServerResponse
import com.auth0.android.request.internal.RequestFactory
Expand Down Expand Up @@ -264,6 +265,48 @@ public class AuthenticationAPIClientTest {
assertThat(registrationResponse.authSession, Matchers.comparesEqualTo(SESSION_ID))
}

@Test
public fun shouldSignupWithPasskeyWithAllUserDataFields() {
mockAPI.willReturnSuccessfulPasskeyRegistration()
val auth0 = auth0
val client = AuthenticationAPIClient(auth0)
val userData = UserData(
email = "test@example.com",
phoneNumber = "+1234567890",
userName = "testuser",
name = "Test User",
givenName = "Test",
familyName = "User",
nickName = "testy",
picture = "https://example.com/photo.png",
userMetadata = mapOf("key1" to "value1")
)
val registrationResponse = client.signupWithPasskey(
userData,
MY_CONNECTION,
"testOrganization"
).execute()
val request = mockAPI.takeRequest()
val body = bodyFromRequest<Any>(request)
assertThat(request.path, Matchers.equalTo("/passkey/register"))
assertThat(body, Matchers.hasKey("user_profile"))
@Suppress("UNCHECKED_CAST")
val userProfile = body["user_profile"] as Map<String, Any>
assertThat(userProfile, Matchers.hasEntry("email", "test@example.com"))
assertThat(userProfile, Matchers.hasEntry("phone_number", "+1234567890"))
assertThat(userProfile, Matchers.hasEntry("username", "testuser"))
assertThat(userProfile, Matchers.hasEntry("name", "Test User"))
assertThat(userProfile, Matchers.hasEntry("given_name", "Test"))
assertThat(userProfile, Matchers.hasEntry("family_name", "User"))
assertThat(userProfile, Matchers.hasEntry("nickname", "testy"))
assertThat(userProfile, Matchers.hasEntry("picture", "https://example.com/photo.png"))
assertThat(userProfile, Matchers.hasKey("user_metadata"))
@Suppress("UNCHECKED_CAST")
val metadata = userProfile["user_metadata"] as Map<String, String>
assertThat(metadata, Matchers.hasEntry("key1", "value1"))
assertThat(registrationResponse, Matchers.`is`(Matchers.notNullValue()))
}

@Test
public fun shouldGetPasskeyChallenge() {
mockAPI.willReturnSuccessfulPasskeyChallenge()
Expand Down
Loading