コンテンツにスキップ
Tauri

Biometric(生体認証)

《訳注》

Plugin 説明内容の英語表記部分について Plugin の各章は、原文データからページ内容の一部が自動生成されているため、英語表記のままの部分があります。

Android および iOS で、ユーザーに「生体認証 biometric authentication」を要求します。

This plugin requires a Rust version of at least 1.77.2

Platform Level Notes
windows
linux
macos
android
ios

はじめに、「Biometric(生体認証)」プラグインをインストールしてください。

自分のプロジェクトのパッケージ・マネージャーを使用して依存関係を追加します:

npm run tauri add biometric

iOS では、「Biometric(生体認証)」プラグインに、あなたのアプリが「生体認証」を使用する理由を説明する NSFaceIDUsageDescription 情報プロパティ・リストの値が必要です。

src-tauri/Info.ios.plist ファイルには、以下のスニペット(内容)を追加してください:

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>

このプラグインを使用すると、デバイス上で生体認証が利用可能かどうかを確認し、ユーザーに生体認証を要求し、その結果を検証して認証が成功したかどうかを判断できるようになります。

生体認証が利用可能か、どのタイプの生体認証方法がサポートされているのか、などをはじめとして、「生体認証」の状態(ステータス)を確認できます。

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
);
}

ユーザーに「生体認証」を要求するには、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);
}

デフォルトでは、潜在的に危険なプラグイン・コマンドとそのスコープ(有効範囲)はすべてブロックされており、アクセスできません。これらを有効にするには、capabilities 設定でアクセス権限を変更する必要があります。

詳細については「セキュリティ・レベル Capabilities」の章を参照してください。また、プラグインのアクセス権限を設定するには「プライグン・アクセス権の使用」の章のステップ・バイ・ステップ・ガイドを参照してください。

src-tauri/capabilities/default.json
{
"$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 acccess to all biometric commands.

This default permission set includes the following:

  • allow-authenticate
  • allow-status

Permission Table

Identifier Description

biometric:allow-authenticate

Enables the authenticate command without any pre-configured scope.

biometric:deny-authenticate

Denies the authenticate command without any pre-configured scope.

biometric:allow-status

Enables the status command without any pre-configured scope.

biometric:deny-status

Denies the status command without any pre-configured scope.

【※ この日本語版は、「Jul 1, 2025 英語版」に基づいています】


© 2025 Tauri Contributors. CC-BY / MIT