-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c982159
commit 96c94de
Showing
1 changed file
with
23 additions
and
0 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
webauthn/android/src/main/java/expo/modules/webauthn/ExpoWebauthn.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,33 @@ | ||
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.core.logging.Logger | ||
import expo.modules.core.logging.LoggerOptions | ||
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())) | ||
) | ||
} | ||
} | ||
} |