mirror of
https://github.com/tauri-apps/plugins-workspace.git
synced 2026-06-06 13:53:54 +02:00
feat(plugins): inject API on window.__TAURI__ (#383)
This commit is contained in:
committed by
GitHub
parent
3c8577bc9a
commit
b131bc8f7c
@@ -2,15 +2,19 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import { invoke } from "@tauri-apps/api/tauri";
|
||||
declare global {
|
||||
interface Window {
|
||||
__TAURI_INVOKE__: <T>(cmd: string, args?: unknown) => Promise<T>;
|
||||
}
|
||||
}
|
||||
|
||||
export class Authenticator {
|
||||
async init(): Promise<void> {
|
||||
return await invoke("plugin:authenticator|init_auth");
|
||||
return await window.__TAURI_INVOKE__("plugin:authenticator|init_auth");
|
||||
}
|
||||
|
||||
async register(challenge: string, application: string): Promise<string> {
|
||||
return await invoke("plugin:authenticator|register", {
|
||||
return await window.__TAURI_INVOKE__("plugin:authenticator|register", {
|
||||
timeout: 10000,
|
||||
challenge,
|
||||
application,
|
||||
@@ -23,12 +27,15 @@ export class Authenticator {
|
||||
registerData: string,
|
||||
clientData: string
|
||||
): Promise<string> {
|
||||
return await invoke("plugin:authenticator|verify_registration", {
|
||||
challenge,
|
||||
application,
|
||||
registerData,
|
||||
clientData,
|
||||
});
|
||||
return await window.__TAURI_INVOKE__(
|
||||
"plugin:authenticator|verify_registration",
|
||||
{
|
||||
challenge,
|
||||
application,
|
||||
registerData,
|
||||
clientData,
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
async sign(
|
||||
@@ -36,7 +43,7 @@ export class Authenticator {
|
||||
application: string,
|
||||
keyHandle: string
|
||||
): Promise<string> {
|
||||
return await invoke("plugin:authenticator|sign", {
|
||||
return await window.__TAURI_INVOKE__("plugin:authenticator|sign", {
|
||||
timeout: 10000,
|
||||
challenge,
|
||||
application,
|
||||
@@ -52,13 +59,16 @@ export class Authenticator {
|
||||
keyHandle: string,
|
||||
pubkey: string
|
||||
): Promise<number> {
|
||||
return await invoke("plugin:authenticator|verify_signature", {
|
||||
challenge,
|
||||
application,
|
||||
signData,
|
||||
clientData,
|
||||
keyHandle,
|
||||
pubkey,
|
||||
});
|
||||
return await window.__TAURI_INVOKE__(
|
||||
"plugin:authenticator|verify_signature",
|
||||
{
|
||||
challenge,
|
||||
application,
|
||||
signData,
|
||||
clientData,
|
||||
keyHandle,
|
||||
pubkey,
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
if("__TAURI__"in window){var __TAURI_AUTHENTICATOR__=function(t){"use strict";return t.Authenticator=class{async init(){return await window.__TAURI_INVOKE__("plugin:authenticator|init_auth")}async register(t,i){return await window.__TAURI_INVOKE__("plugin:authenticator|register",{timeout:1e4,challenge:t,application:i})}async verifyRegistration(t,i,a,n){return await window.__TAURI_INVOKE__("plugin:authenticator|verify_registration",{challenge:t,application:i,registerData:a,clientData:n})}async sign(t,i,a){return await window.__TAURI_INVOKE__("plugin:authenticator|sign",{timeout:1e4,challenge:t,application:i,keyHandle:a})}async verifySignature(t,i,a,n,e,_){return await window.__TAURI_INVOKE__("plugin:authenticator|verify_signature",{challenge:t,application:i,signData:a,clientData:n,keyHandle:e,pubkey:_})}},t}({});Object.defineProperty(window.__TAURI__,"authenticator",{value:__TAURI_AUTHENTICATOR__})}
|
||||
@@ -67,6 +67,7 @@ fn verify_signature(
|
||||
|
||||
pub fn init<R: Runtime>() -> TauriPlugin<R> {
|
||||
PluginBuilder::new("authenticator")
|
||||
.js_init_script(include_str!("api-iife.js").to_string())
|
||||
.invoke_handler(tauri::generate_handler![
|
||||
init_auth,
|
||||
register,
|
||||
|
||||
Reference in New Issue
Block a user