-
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
f4c530a
commit 40f9c4e
Showing
1 changed file
with
21 additions
and
0 deletions.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
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,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())) | ||
) | ||
} | ||
} | ||
} |