mirror of
https://github.com/tauri-apps/plugins-workspace.git
synced 2026-04-29 12:06:01 +02:00
Merge branch 'dev' into next. Rename next to v2
This commit is contained in:
@@ -20,7 +20,7 @@ Install the Core plugin by adding the following to your `Cargo.toml` file:
|
||||
[dependencies]
|
||||
tauri-plugin-authenticator = "0.1"
|
||||
# or through git
|
||||
tauri-plugin-authenticator = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "next" }
|
||||
tauri-plugin-authenticator = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v2" }
|
||||
```
|
||||
|
||||
You can install the JavaScript Guest bindings using your preferred JavaScript package manager:
|
||||
@@ -28,11 +28,11 @@ You can install the JavaScript Guest bindings using your preferred JavaScript pa
|
||||
> Note: Since most JavaScript package managers are unable to install packages from git monorepos we provide read-only mirrors of each plugin. This makes installation option 2 more ergonomic to use.
|
||||
|
||||
```sh
|
||||
pnpm add https://github.com/tauri-apps/tauri-plugin-authenticator#next
|
||||
pnpm add https://github.com/tauri-apps/tauri-plugin-authenticator#v2
|
||||
# or
|
||||
npm add https://github.com/tauri-apps/tauri-plugin-authenticator#next
|
||||
npm add https://github.com/tauri-apps/tauri-plugin-authenticator#v2
|
||||
# or
|
||||
yarn add https://github.com/tauri-apps/tauri-plugin-authenticator#next
|
||||
yarn add https://github.com/tauri-apps/tauri-plugin-authenticator#v2
|
||||
```
|
||||
|
||||
## Usage
|
||||
@@ -53,7 +53,7 @@ fn main() {
|
||||
Afterwards all the plugin's APIs are available through the JavaScript guest bindings:
|
||||
|
||||
```javascript
|
||||
import { Authenticator } from 'tauri-plugin-authenticator-api';
|
||||
import { Authenticator } from "tauri-plugin-authenticator-api";
|
||||
|
||||
const auth = new Authenticator();
|
||||
auth.init(); // initialize transports
|
||||
@@ -63,16 +63,21 @@ const arr = new Uint32Array(32);
|
||||
window.crypto.getRandomValues(arr);
|
||||
const b64 = btoa(String.fromCharCode.apply(null, arr));
|
||||
// web-safe base64
|
||||
const challenge = b64.replace(/\+/g, '-').replace(/\//g, '_');
|
||||
const challenge = b64.replace(/\+/g, "-").replace(/\//g, "_");
|
||||
|
||||
const domain = 'https://tauri.app';
|
||||
const domain = "https://tauri.app";
|
||||
|
||||
// attempt to register with the security key
|
||||
const json = await auth.register(challenge, domain);
|
||||
const registerResult = JSON.parse(json);
|
||||
|
||||
// verify te registration was successfull
|
||||
const r2 = await auth.verifyRegistration(challenge, app, registerResult.registerData, registerResult.clientData);
|
||||
const r2 = await auth.verifyRegistration(
|
||||
challenge,
|
||||
app,
|
||||
registerResult.registerData,
|
||||
registerResult.clientData
|
||||
);
|
||||
const j2 = JSON.parse(r2);
|
||||
|
||||
// sign some data
|
||||
@@ -80,10 +85,17 @@ const json = await auth.sign(challenge, app, keyHandle);
|
||||
const signData = JSON.parse(json);
|
||||
|
||||
// verify the signature again
|
||||
const counter = await auth.verifySignature(challenge, app, signData.signData, clientData, keyHandle, pubkey);
|
||||
const counter = await auth.verifySignature(
|
||||
challenge,
|
||||
app,
|
||||
signData.signData,
|
||||
clientData,
|
||||
keyHandle,
|
||||
pubkey
|
||||
);
|
||||
|
||||
if (counter && counter > 0) {
|
||||
console.log('SUCCESS!');
|
||||
console.log("SUCCESS!");
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
Reference in New Issue
Block a user