@parlor/capacitor-device-key 0.1.0 → 0.2.0
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.
package/dist/index.d.ts
CHANGED
|
@@ -30,6 +30,15 @@ export interface ParlorSessionStorePlugin {
|
|
|
30
30
|
value?: string;
|
|
31
31
|
}): Promise<void>;
|
|
32
32
|
}
|
|
33
|
+
export interface ParlorAuthBrowserPlugin {
|
|
34
|
+
open(options: {
|
|
35
|
+
url: string;
|
|
36
|
+
callbackScheme: string;
|
|
37
|
+
}): Promise<{
|
|
38
|
+
url?: string;
|
|
39
|
+
}>;
|
|
40
|
+
}
|
|
33
41
|
export declare const ParlorDeviceKey: ParlorDeviceKeyPlugin;
|
|
34
42
|
export declare const ParlorSessionStore: ParlorSessionStorePlugin;
|
|
43
|
+
export declare const ParlorAuthBrowser: ParlorAuthBrowserPlugin;
|
|
35
44
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,qBAAqB;IACpC,UAAU,CAAC,OAAO,EAAE;QAAE,QAAQ,EAAE,OAAO,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC;QACrE,OAAO,EAAE;YAAE,KAAK,EAAE,MAAM,CAAC;YAAC,SAAS,EAAE,UAAU,CAAA;SAAE,CAAC;QAClD,QAAQ,CAAC,EAAE;YAAE,KAAK,EAAE,MAAM,CAAC;YAAC,SAAS,EAAE,UAAU,CAAA;SAAE,CAAC;QACpD,KAAK,EAAE;YAAE,SAAS,EAAE,MAAM,CAAA;SAAE,CAAC;KAC9B,CAAC,CAAC;IACH,IAAI,CAAC,OAAO,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,C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D;AAED,MAAM,WAAW,uBAAuB;IACtC,IAAI,CAAC,OAAO,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,cAAc,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC;QAAE,GAAG,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CACnF;AAED,eAAO,MAAM,eAAe,uBAA2D,CAAC;AACxF,eAAO,MAAM,kBAAkB,0BACiC,CAAC;AACjE,eAAO,MAAM,iBAAiB,yBACgC,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { registerPlugin } from "@capacitor/core";
|
|
2
2
|
export const ParlorDeviceKey = registerPlugin("ParlorDeviceKey");
|
|
3
3
|
export const ParlorSessionStore = registerPlugin("ParlorSessionStore");
|
|
4
|
+
export const ParlorAuthBrowser = registerPlugin("ParlorAuthBrowser");
|
|
4
5
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAoBjD,MAAM,CAAC,MAAM,eAAe,GAAG,cAAc,CAAwB,iBAAiB,CAAC,CAAC;AACxF,MAAM,CAAC,MAAM,kBAAkB,GAC7B,cAAc,CAA2B,oBAAoB,CAAC,CAAC;AACjE,MAAM,CAAC,MAAM,iBAAiB,GAC5B,cAAc,CAA0B,mBAAmB,CAAC,CAAC","sourcesContent":["import { registerPlugin } from \"@capacitor/core\";\n\nexport interface ParlorDeviceKeyPlugin {\n publicKeys(options: { presence: boolean; challenge: string }): Promise<{\n signing: { keyId: string; publicKey: JsonWebKey };\n presence?: { keyId: string; publicKey: JsonWebKey };\n proof: { signature: string };\n }>;\n sign(options: { keyId: string; payload: string }): Promise<{ signature: string }>;\n}\n\nexport interface ParlorSessionStorePlugin {\n get(): Promise<{ value?: string }>;\n set(options: { value?: string }): Promise<void>;\n}\n\nexport interface ParlorAuthBrowserPlugin {\n open(options: { url: string; callbackScheme: string }): Promise<{ url?: string }>;\n}\n\nexport const ParlorDeviceKey = registerPlugin<ParlorDeviceKeyPlugin>(\"ParlorDeviceKey\");\nexport const ParlorSessionStore =\n registerPlugin<ParlorSessionStorePlugin>(\"ParlorSessionStore\");\nexport const ParlorAuthBrowser =\n registerPlugin<ParlorAuthBrowserPlugin>(\"ParlorAuthBrowser\");\n"]}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import AuthenticationServices
|
|
2
|
+
import Capacitor
|
|
3
|
+
import Foundation
|
|
4
|
+
|
|
5
|
+
@objc(ParlorAuthBrowserPlugin)
|
|
6
|
+
public class ParlorAuthBrowserPlugin: CAPPlugin, CAPBridgedPlugin,
|
|
7
|
+
ASWebAuthenticationPresentationContextProviding
|
|
8
|
+
{
|
|
9
|
+
public let identifier = "ParlorAuthBrowserPlugin"
|
|
10
|
+
public let jsName = "ParlorAuthBrowser"
|
|
11
|
+
public let pluginMethods: [CAPPluginMethod] = [
|
|
12
|
+
CAPPluginMethod(name: "open", returnType: CAPPluginReturnPromise)
|
|
13
|
+
]
|
|
14
|
+
|
|
15
|
+
private var session: ASWebAuthenticationSession?
|
|
16
|
+
|
|
17
|
+
@objc func open(_ call: CAPPluginCall) {
|
|
18
|
+
guard let address = call.getString("url"), let url = URL(string: address),
|
|
19
|
+
url.scheme == "https" || url.scheme == "http",
|
|
20
|
+
let scheme = call.getString("callbackScheme"), !scheme.isEmpty
|
|
21
|
+
else {
|
|
22
|
+
call.reject("An http(s) url and a callbackScheme are required.")
|
|
23
|
+
return
|
|
24
|
+
}
|
|
25
|
+
DispatchQueue.main.async {
|
|
26
|
+
self.session?.cancel()
|
|
27
|
+
var running: ASWebAuthenticationSession?
|
|
28
|
+
let session = ASWebAuthenticationSession(url: url, callbackURLScheme: scheme) {
|
|
29
|
+
[weak self] callback, error in
|
|
30
|
+
if let self, self.session === running { self.session = nil }
|
|
31
|
+
running = nil
|
|
32
|
+
if let callback {
|
|
33
|
+
call.resolve(["url": callback.absoluteString])
|
|
34
|
+
} else if let error = error as? ASWebAuthenticationSessionError,
|
|
35
|
+
error.code == .canceledLogin
|
|
36
|
+
{
|
|
37
|
+
call.resolve([:])
|
|
38
|
+
} else {
|
|
39
|
+
call.reject(error?.localizedDescription ?? "Sign-in did not finish.")
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
session.presentationContextProvider = self
|
|
43
|
+
running = session
|
|
44
|
+
self.session = session
|
|
45
|
+
if !session.start() {
|
|
46
|
+
self.session = nil
|
|
47
|
+
running = nil
|
|
48
|
+
call.reject("The sign-in browser could not open.")
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
public func presentationAnchor(for session: ASWebAuthenticationSession)
|
|
54
|
+
-> ASPresentationAnchor
|
|
55
|
+
{
|
|
56
|
+
bridge?.webView?.window ?? ASPresentationAnchor()
|
|
57
|
+
}
|
|
58
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@parlor/capacitor-device-key",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Capacitor plugins for the device key and the session store, backed by the iOS keystore",
|
|
5
5
|
"homepage": "https://cychien.github.io/parlor",
|
|
6
6
|
"bugs": "https://github.com/cychien/parlor/issues",
|