Skip to content

Commit

Permalink
Merge pull request #36 from passageidentity/add-passkey-update
Browse files Browse the repository at this point in the history
Added optional `options` argument to `user.addDevicePasskey` method
  • Loading branch information
rickycpadilla authored May 7, 2024
2 parents 9bd4480 + 021ed41 commit 96d933f
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Integrating passkey technology can be really hard. That's why we built the Passa

You can import the Passage library by including this in your app's `build.gradle` file dependencies:
```gradle
implementation 'id.passage.android:passage:1.7.0'
implementation 'id.passage.android:passage:1.7.1'
```

And you can use it like this:
Expand Down
6 changes: 3 additions & 3 deletions passage/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ apply plugin: 'maven-publish'
apply plugin: 'signing'

group = "id.passage.android"
version = "1.7.0"
version = "1.7.1"

def localProperties = new Properties()
File localPropertiesFile = rootProject.file('local.properties')
Expand All @@ -30,8 +30,8 @@ android {
defaultConfig {
minSdk 28 // Minimum support for Credentials Manager - ie passkeys
targetSdk 34
versionCode 11
versionName "1.7.0"
versionCode 12
versionName "1.7.1"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down
22 changes: 20 additions & 2 deletions passage/fix_generated_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,26 @@
# User model requires `webauthn_types` property, but webauthn start returns user WITHOUT it, so we must make it optional.
(
'./generated/src/main/kotlin/id/passage/android/model/User.kt',
'val webauthnTypes: kotlin.collections.List<WebAuthnType>',
'val webauthnTypes: kotlin.collections.List<WebAuthnType>?'
'''val webauthnTypes: kotlin.collections.List<WebAuthnType>
''',
'''val webauthnTypes: kotlin.collections.List<WebAuthnType>?
'''
),

# Some endpoints return a user with a status set to "". This is incompatible with the spec, so we have to add the statusUnavailable option.
(
'./generated/src/main/kotlin/id/passage/android/model/UserStatus.kt',
'''@Json(name = "pending")
pending("pending");
''',
'''@Json(name = "pending")
pending("pending"),
@Json(name = "")
statusUnavailable("");
'''
),

# Add more replacements here as needed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,11 @@ enum class UserStatus(val value: kotlin.String) {
inactive("inactive"),

@Json(name = "pending")
pending("pending");
pending("pending"),

@Json(name = "")
statusUnavailable("");

/**
* Override toString() to avoid using the enum variable name as the value, and instead use
* the actual value defined in the API spec file.
Expand Down
1 change: 1 addition & 0 deletions passage/src/main/java/id/passage/android/Passage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ public final class Passage(
*
* Create a user, prompt the user to create a passkey, and register the user.
* @param identifier valid email or E164 phone number
* @param options optional configuration for passkey creation
* @return PassageAuthResult
* @throws RegisterWithPasskeyException
*/
Expand Down
14 changes: 12 additions & 2 deletions passage/src/main/java/id/passage/android/PassageUser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import id.passage.android.api.CurrentuserAPI
import id.passage.android.exceptions.AddDevicePasskeyException
import id.passage.android.exceptions.PassageUserException
import id.passage.android.model.AddDeviceFinishRequest
import id.passage.android.model.AuthenticatorAttachment
import id.passage.android.model.CurrentUser
import id.passage.android.model.CurrentUserDevicesStartRequest
import id.passage.android.model.MagicLink
import id.passage.android.model.UpdateDeviceRequest
import id.passage.android.model.UpdateUserEmailRequest
Expand Down Expand Up @@ -183,14 +185,22 @@ final class PassageUser private constructor(
*
* Returns the created device for the user. User must be authenticated via a bearer token.
* @param activity Activity to surface the Credentials Manager prompt within
* @param options optional configuration for passkey creation
* @return PassageCredential
* @throws AddDevicePasskeyException
*/
public suspend fun addDevicePasskey(activity: Activity): PassageCredential {
public suspend fun addDevicePasskey(
activity: Activity,
options: PasskeyCreationOptions? = null,
): PassageCredential {
try {
val currentUserAPI = CurrentuserAPI(Passage.BASE_PATH)
// Get Create Credential challenge from Passage
val webauthnStartResponse = currentUserAPI.postCurrentuserAddDeviceStart(Passage.appId)
val authenticatorAttachment =
options?.authenticatorAttachment
?: AuthenticatorAttachment.platform
val request = CurrentUserDevicesStartRequest(authenticatorAttachment)
val webauthnStartResponse = currentUserAPI.postCurrentuserAddDeviceStart(Passage.appId, request)
// Use Create Credential challenge to prompt user to create a passkey
val createCredOptionsJson = PasskeyUtils.getCreateCredentialOptionsJson(webauthnStartResponse.handshake)
val createCredResponse = PasskeyUtils.createPasskey(createCredOptionsJson, activity)
Expand Down

0 comments on commit 96d933f

Please sign in to comment.