UserConsentVerifier クラス
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
検証デバイス (Microsoft Passport PIN、Windows Hello生体認証、指紋リーダーなど) の可用性を確認し、検証を実行します。
public ref class UserConsentVerifier abstract sealed
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
class UserConsentVerifier final
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
public static class UserConsentVerifier
Public Class UserConsentVerifier
- 継承
- 属性
Windows の要件
デバイス ファミリ |
Windows 10 (10.0.10240.0 で導入)
|
API contract |
Windows.Foundation.UniversalApiContract (v1.0 で導入)
|
例
C を使用したデスクトップ アプリ#
デスクトップ アプリの場合、 UserConsentVerifier.RequestVerificationAsync メソッドを呼び出す代わりに、次の操作を行う必要があります。
- 最初 にウィンドウ ハンドル (HWND) を取得します。 このトピックには、Windows UI ライブラリ (WinUI) 3、Windows Presentation Foundation (WPF)、Windows フォーム (WinForms) のコード例が含まれています。 そのコードを以下のコード一覧にプラグインします。
- 次に、Windows.Security.Credentials.UI.UserConsentVerifierInterop C# 相互運用クラスの RequestVerificationForWindowAsync メソッドを呼び出します。 C# 相互運用クラスの詳細については、「 .NET アプリから相互運用 API を呼び出す」を参照してください。 「 CoreWindow に依存する WinRT UI オブジェクトを表示する」も参照してください。
private async System.Threading.Tasks.Task<string> RequestConsent(string userMessage)
{
string returnMessage;
if (String.IsNullOrEmpty(userMessage))
{
userMessage = "Please provide fingerprint verification.";
}
try
{
// Retrieve the window handle by passing a reference to the WinUI 3 window object
var hwnd = ...
// Request the logged on user's consent via fingerprint swipe using the interop interface
var consentResult = await Windows.Security.Credentials.UI.UserConsentVerifierInterop.RequestVerificationForWindowAsync(hwnd, userMessage);
switch (consentResult)
{
case Windows.Security.Credentials.UI.UserConsentVerificationResult.Verified:
returnMessage = "Fingerprint verified.";
break;
case Windows.Security.Credentials.UI.UserConsentVerificationResult.DeviceBusy:
returnMessage = "Biometric device is busy.";
break;
case Windows.Security.Credentials.UI.UserConsentVerificationResult.DeviceNotPresent:
returnMessage = "No biometric device found.";
break;
case Windows.Security.Credentials.UI.UserConsentVerificationResult.DisabledByPolicy:
returnMessage = "Biometric verification is disabled by policy.";
break;
case Windows.Security.Credentials.UI.UserConsentVerificationResult.NotConfiguredForUser:
returnMessage = "The user has no fingerprints registered. Please add a fingerprint to the " +
"fingerprint database and try again.";
break;
case Windows.Security.Credentials.UI.UserConsentVerificationResult.RetriesExhausted:
returnMessage = "There have been too many failed attempts. Fingerprint authentication canceled.";
break;
case Windows.Security.Credentials.UI.UserConsentVerificationResult.Canceled:
returnMessage = "Fingerprint authentication canceled.";
break;
default:
returnMessage = "Fingerprint authentication is currently unavailable.";
break;
}
}
catch (Exception ex)
{
returnMessage = "Fingerprint authentication failed: " + ex.ToString();
}
return returnMessage;
}
C を使用したユニバーサル Windows プラットフォーム (UWP) アプリ#
このコード例は、ユニバーサル Windows プラットフォーム (UWP) アプリ用です。 指紋認証の要求の後に、結果を説明するメッセージを返すメッセージが表示されます。 このコードは、UWP アプリに適した UserConsentVerifier.RequestVerificationAsync メソッドを呼び出します。
private async System.Threading.Tasks.Task<string> RequestConsent(string userMessage)
{
string returnMessage;
if (String.IsNullOrEmpty(userMessage))
{
userMessage = "Please provide fingerprint verification.";
}
try
{
// Request the logged on user's consent via fingerprint swipe.
var consentResult = await Windows.Security.Credentials.UI.UserConsentVerifier.RequestVerificationAsync(userMessage);
switch (consentResult)
{
case Windows.Security.Credentials.UI.UserConsentVerificationResult.Verified:
returnMessage = "Fingerprint verified.";
break;
case Windows.Security.Credentials.UI.UserConsentVerificationResult.DeviceBusy:
returnMessage = "Biometric device is busy.";
break;
case Windows.Security.Credentials.UI.UserConsentVerificationResult.DeviceNotPresent:
returnMessage = "No biometric device found.";
break;
case Windows.Security.Credentials.UI.UserConsentVerificationResult.DisabledByPolicy:
returnMessage = "Biometric verification is disabled by policy.";
break;
case Windows.Security.Credentials.UI.UserConsentVerificationResult.NotConfiguredForUser:
returnMessage = "The user has no fingerprints registered. Please add a fingerprint to the " +
"fingerprint database and try again.";
break;
case Windows.Security.Credentials.UI.UserConsentVerificationResult.RetriesExhausted:
returnMessage = "There have been too many failed attempts. Fingerprint authentication canceled.";
break;
case Windows.Security.Credentials.UI.UserConsentVerificationResult.Canceled:
returnMessage = "Fingerprint authentication canceled.";
break;
default:
returnMessage = "Fingerprint authentication is currently unavailable.";
break;
}
}
catch (Exception ex)
{
returnMessage = "Fingerprint authentication failed: " + ex.ToString();
}
return returnMessage;
}
注釈
UserConsentVerifier を使用すると、ユーザーが特定のアクションに同意する必要がある場合は常に検証要求を含めることで、アプリのセキュリティを強化できます。 たとえば、アプリ内購入や制限付きリソースへのアクセスを承認する前に、指紋認証を要求できます。 UserConsentVerifier を使用すると、CheckAvailabilityAsync メソッドを使用して現在のコンピューターで指紋認証がサポートされているかどうかを判断し、RequestVerificationAsync メソッドを使用して指紋スキャンにユーザーの同意を要求できます。
メソッド
CheckAvailabilityAsync() |
検証ツール デバイス (Microsoft Passport PIN、Windows Hello、指紋リーダーなど) を使用できるかどうかを確認します。 |
RequestVerificationAsync(String) |
Microsoft Passport PIN、Windows Hello、指紋リーダーなどのデバイスを使用して検証を実行します。 この API は、ユニバーサル Windows プラットフォーム (UWP) アプリ用です。 デスクトップ アプリに使用する代替 API については、「UserConsentVerifier クラスの例」を参照してください。 |
適用対象
こちらもご覧ください
フィードバック
https://aka.ms/ContentUserFeedback」を参照してください。
以下は間もなく提供いたします。2024 年を通じて、コンテンツのフィードバック メカニズムとして GitHub の issue を段階的に廃止し、新しいフィードバック システムに置き換えます。 詳細については、「フィードバックの送信と表示