Skip to content

Commit

Permalink
✨ webauthn: implement for android
Browse files Browse the repository at this point in the history
  • Loading branch information
cruzdanilo committed Nov 14, 2023
1 parent f4c530a commit 40f9c4e
Showing 1 changed file with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,31 @@
package expo.modules.webauthn

import androidx.credentials.CreatePublicKeyCredentialRequest
import androidx.credentials.CredentialManager
import androidx.credentials.GetCredentialRequest
import androidx.credentials.GetPasswordOption
import androidx.credentials.GetPublicKeyCredentialOption
import expo.modules.kotlin.exception.Exceptions
import expo.modules.kotlin.functions.Coroutine
import expo.modules.kotlin.modules.Module
import expo.modules.kotlin.modules.ModuleDefinition

class ExpoWebauthn : Module() {
override fun definition() = ModuleDefinition {
Name("ExpoWebauthn")

AsyncFunction("create") Coroutine { requestJSON: String ->
val activity = appContext.currentActivity ?: throw Exceptions.MissingActivity()
CredentialManager.create(activity)
.createCredential(activity, CreatePublicKeyCredentialRequest(requestJSON))
}

AsyncFunction("get") Coroutine { requestJSON: String ->
val activity = appContext.currentActivity ?: throw Exceptions.MissingActivity()
CredentialManager.create(activity).getCredential(
activity,
GetCredentialRequest(listOf(GetPublicKeyCredentialOption(requestJSON), GetPasswordOption()))
)
}
}
}

0 comments on commit 40f9c4e

Please sign in to comment.