@tokamakdev/plugin-local-authentication 0.1.0-beta.48 → 0.1.0-beta.50

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,21 +1,21 @@
1
1
  package com.tokamak.plugins.localauthentication
2
2
 
3
- import android.app.Activity
4
3
  import android.hardware.biometrics.BiometricManager
5
4
  import android.hardware.biometrics.BiometricManager.Authenticators
6
5
  import android.hardware.biometrics.BiometricPrompt
7
6
  import android.os.CancellationSignal
7
+ import com.tokamak.runtime.TokamakHost
8
8
  import com.tokamak.runtime.TokamakPlugin
9
9
  import com.tokamak.runtime.TokamakPluginError
10
10
  import com.tokamak.runtime.TokamakPluginReply
11
11
  import org.json.JSONObject
12
12
 
13
- internal class TokamakLocalAuthenticationPlugin(
14
- private val activity: Activity,
13
+ class TokamakLocalAuthenticationPlugin(
14
+ private val host: TokamakHost,
15
15
  ) : TokamakPlugin {
16
16
  override val id = "local-authentication"
17
17
 
18
- private val biometrics = activity.getSystemService(BiometricManager::class.java)
18
+ private val biometrics = host.context.getSystemService(BiometricManager::class.java)
19
19
 
20
20
  override fun call(method: String, arguments: Any?, reply: TokamakPluginReply) {
21
21
  when (method) {
@@ -41,6 +41,7 @@ internal class TokamakLocalAuthenticationPlugin(
41
41
  val prompt = request.requireString("prompt")
42
42
  if (prompt.isEmpty()) throw typeError("prompt must be a non-empty string")
43
43
  requireAvailable(authenticators)
44
+ val activity = host.activity ?: throw notVisible()
44
45
  val callback = PromptCallback(reply) { reply(Result.success(null)) }
45
46
  val dialog =
46
47
  BiometricPrompt.Builder(activity)
@@ -99,6 +100,9 @@ internal class TokamakLocalAuthenticationPlugin(
99
100
  fun notSetUp() =
100
101
  TokamakPluginError("InvalidStateError", "The requested authentication is not set up on this device")
101
102
 
103
+ fun notVisible() =
104
+ TokamakPluginError("InvalidStateError", "The app has no activity to show the authentication prompt in")
105
+
102
106
  fun pluginError(error: Throwable): TokamakPluginError =
103
107
  error as? TokamakPluginError
104
108
  ?: TokamakPluginError("OperationError", error.message ?: error.javaClass.name)
@@ -0,0 +1,8 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
+ <plist version="1.0">
4
+ <dict>
5
+ <key>NSFaceIDUsageDescription</key>
6
+ <string>This app uses Face ID to confirm your identity.</string>
7
+ </dict>
8
+ </plist>
@@ -4,6 +4,8 @@ import LocalAuthentication
4
4
  final class TokamakLocalAuthenticationPlugin: TokamakPlugin {
5
5
  let id = "local-authentication"
6
6
 
7
+ init(host: TokamakHost) {}
8
+
7
9
  func call(
8
10
  method: String,
9
11
  arguments: Any,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tokamakdev/plugin-local-authentication",
3
- "version": "0.1.0-beta.48",
3
+ "version": "0.1.0-beta.50",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/mantty/tokamak.git",
@@ -11,7 +11,7 @@
11
11
  ".": "./src/index.ts"
12
12
  },
13
13
  "dependencies": {
14
- "@tokamakdev/plugin": "0.1.0-beta.48"
14
+ "@tokamakdev/plugin": "0.1.0-beta.50"
15
15
  },
16
16
  "files": [
17
17
  "android",
@@ -1,7 +1,6 @@
1
1
  {
2
2
  "schemaVersion": 1,
3
3
  "id": "local-authentication",
4
- "kind": "frontend",
5
4
  "platforms": {
6
5
  "macos": {
7
6
  "class": "TokamakLocalAuthenticationPlugin",
@@ -12,17 +11,13 @@
12
11
  "class": "TokamakLocalAuthenticationPlugin",
13
12
  "sources": ["apple/LocalAuthenticationPlugin.swift"],
14
13
  "frameworks": ["LocalAuthentication"],
15
- "plist": {
16
- "NSFaceIDUsageDescription": "This app uses Face ID to confirm your identity."
17
- }
14
+ "plist": "apple/Info.plist"
18
15
  },
19
16
  "ios-simulator": {
20
17
  "class": "TokamakLocalAuthenticationPlugin",
21
18
  "sources": ["apple/LocalAuthenticationPlugin.swift"],
22
19
  "frameworks": ["LocalAuthentication"],
23
- "plist": {
24
- "NSFaceIDUsageDescription": "This app uses Face ID to confirm your identity."
25
- }
20
+ "plist": "apple/Info.plist"
26
21
  },
27
22
  "android": {
28
23
  "class": "com.tokamak.plugins.localauthentication.TokamakLocalAuthenticationPlugin",