Biometric(生体認証)
Plugin 説明内容の英語表記部分について Plugin の各章は、原文データからページ内容の一部が自動生成されているため、英語表記のままの部分があります。
Android および iOS で、ユーザーに「生体認証 biometric authentication」を要求します。
対応プラットフォーム
Section titled “対応プラットフォーム”This plugin requires a Rust version of at least 1.90
| Platform | Level | Notes |
|---|---|---|
| windows | ||
| linux | ||
| macos | ||
| android | ||
| ios |
セットアップ
Section titled “セットアップ”はじめに、「Biometric(生体認証)」プラグインをインストールしてください。
自分のプロジェクトのパッケージ・マネージャーを使用して依存関係を追加します:
npm run tauri add biometricyarn run tauri add biometricpnpm tauri add biometricdeno task tauri add biometricbun tauri add biometriccargo tauri add biometric-
src-tauriフォルダで次のコマンドを実行して、Cargo.toml内のプロジェクトの依存関係にこのプラグインを追加します:cargo add tauri-plugin-biometric --target 'cfg(any(target_os = "android", target_os = "ios"))' -
追加したプラグインを初期化するために
lib.rsを修正します:src-tauri/src/lib.rs #[cfg_attr(mobile, tauri::mobile_entry_point)]pub fn run() {tauri::Builder::default().setup(|app| {#[cfg(mobile)]app.handle().plugin(tauri_plugin_biometric::Builder::new().build());Ok(())}).run(tauri::generate_context!()).expect("error while running tauri application");} -
お好みの JavaScript パッケージ・マネージャーを使用して、「JavaScript Guide」バインディングをインストールします:
npm install @tauri-apps/plugin-biometricyarn add @tauri-apps/plugin-biometricpnpm add @tauri-apps/plugin-biometricdeno add npm:@tauri-apps/plugin-biometricbun add @tauri-apps/plugin-biometric
iOS では、「Biometric(生体認証)」プラグインに、あなたのアプリが「生体認証」を使用する理由を説明する NSFaceIDUsageDescription 情報プロパティ・リストの値が必要です。
src-tauri/Info.ios.plist ファイルには、以下のスニペット(内容)を追加してください:
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"><plist version="1.0"> <dict> <key>NSFaceIDUsageDescription</key> <string>Authenticate with biometric</string> </dict></plist>このプラグインを使用すると、デバイス上で生体認証が利用可能かどうかを確認し、ユーザーに生体認証を要求し、その結果を検証して認証が成功したかどうかを判断できるようになります。
プラグインの状態確認
Section titled “プラグインの状態確認”生体認証が利用可能か、どのタイプの生体認証方法がサポートされているのか、などをはじめとして、「生体認証」の状態(ステータス)を確認できます。
import { checkStatus } from '@tauri-apps/plugin-biometric';
const status = await checkStatus();if (status.isAvailable) { console.log('Yes! Biometric Authentication is available');} else { console.log( 'No! Biometric Authentication is not available due to ' + status.error );}use tauri_plugin_biometric::BiometricExt;
fn check_biometric(app_handle: tauri::AppHandle) { let status = app_handle.biometric().status().unwrap(); if status.is_available { println!("Yes! Biometric Authentication is available"); } else { println!("No! Biometric Authentication is not available due to: {}", status.error.unwrap()); }}ユーザーに「生体認証」を要求するには、authenticate() メソッドを使用します。
import { authenticate } from '@tauri-apps/plugin-biometric';
const options = { // ユーザーが「電話のパスワード」を使用して認証できるようにするには、true に設定します allowDeviceCredential: false, cancelTitle: "Feature won't work if Canceled",
// iOS のみの機能 fallbackTitle: 'Sorry, authentication failed',
// Android のみの機能 title: 'Tauri feature', subtitle: 'Authenticate to access the locked Tauri function', confirmationRequired: true,};
try { await authenticate('This feature is locked', options); console.log( 'Hooray! Successfully Authenticated! We can now perform the locked Tauri function!' );} catch (err) { console.log('Oh no! Authentication failed because ' + err.message);}use tauri_plugin_biometric::{BiometricExt, AuthOptions};
fn bio_auth(app_handle: tauri::AppHandle) {
let options = AuthOptions { // ユーザーが「電話のパスワード」を使用して認証できるようにするには、true に設定します allow_device_credential:false, cancel_title: Some("Feature won't work if Canceled".to_string()),
// iOS のみの機能 fallback_title: Some("Sorry, authentication failed".to_string()),
// Android のみの機能 title: Some("Tauri feature".to_string()), subtitle: Some("Authenticate to access the locked Tauri function".to_string()), confirmation_required: Some(true), };
// 認証が成功した場合には、関数が Result::Ok() を、 // それ以外の場合には Result::Error() を返します。 match app_handle.biometric().authenticate("This feature is locked".to_string(), options) { Ok(_) => { println!("Hooray! Successfully Authenticated! We can now perform the locked Tauri function!"); } Err(e) => { println!("Oh no! Authentication failed because : {e}"); } }}アクセス権の設定
Section titled “アクセス権の設定”デフォルトでは、潜在的に危険なプラグイン・コマンドとそのスコープ(有効範囲)はすべてブロックされており、アクセスできません。これらを有効にするには、capabilities 設定でアクセス権限を変更する必要があります。
詳細については「セキュリティ・レベル Capabilities」の章を参照してください。また、プラグインのアクセス権限を設定するには「プライグン・アクセス権の使用」の章のステップ・バイ・ステップ・ガイドを参照してください。
{ "$schema": "../gen/schemas/desktop-schema.json", "identifier": "main-capability", "description": "Capability for the main window", "windows": ["main"], "permissions": ["biometric:default"]}Default Permission
This permission set configures which biometric features are by default exposed.
Granted Permissions
It allows checking the biometric status and
prompting for authentication. Encrypting and
decrypting data with biometric_cipher is not
included and must be enabled explicitly with
biometric:allow-biometric-cipher.
This default permission set includes the following:
allow-authenticateallow-status
Permission Table
| Identifier | Description |
|---|---|
|
|
Enables the authenticate command without any pre-configured scope. |
|
|
Denies the authenticate command without any pre-configured scope. |
|
|
Enables the biometric_cipher command without any pre-configured scope. |
|
|
Denies the biometric_cipher command without any pre-configured scope. |
|
|
Enables the status command without any pre-configured scope. |
|
|
Denies the status command without any pre-configured scope. |
【※ この日本語版は、「Jul 1, 2025 英語版」に基づいています】
© 2026 Tauri Contributors. CC-BY / MIT