> ## Documentation Index
> Fetch the complete documentation index at: https://docs-dev-docs-event-stream-action-templates.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# ボット検知をネイティブアプリケーションに追加する

> ボット保護と検知を、Auth0.Swift、Auth0.Android、Lock.Swift、およびLock.Androidを使用するネイティブアプリケーションに追加する方法について説明します。

[ボット検知](/docs/ja-jp/secure/attack-protection/bot-detection)をネイティブアプリケーションに追加する場合、使用するSDKと認証フローによっては、構成をほとんどまたは全く必要としません。

## Auth0.swiftとAuth0.Android

ユニバーサルログインを使用している場合、ボット検知は以下のSDKバージョンによって自動的にサポートされています。

* `Auth0.swift`バージョン1.28.0+
* `Auth0.Android`バージョン1.25.0+

ユニバーサルログインを使用していない場合、ボット検知はサポートされていますが、アプリケーションを適宜構成する必要があります。

* アプリケーションは、`requires_verification`という例外（ログイン試行が高リスクであると判定されると例外をスローする）を処理し、CAPTCHA検証ステップを生じさせるためにWebAuthフローをトリガーする必要があります。
* WebAuthフローをトリガーしたら、ユーザーがユーザー名をもう一度入力する必要がないように、`login_hint`パラメーターを渡してください。

### Auth0.swiftの例

アプリケーションが、[Authentication API](/docs/ja-jp/api/authentication)を通じてデータベースログイン/サインアップを実行する場合は、`isVerificationRequired`エラーを処理する必要があります。このエラーは、要求が疑わしいとフラグが立てられ、ユーザー認証に別の検証ステップが必要であることを示します。

<Callout icon="file-lines" color="#0EA5E9" iconType="regular">
  この検証ステップはWebベースであるため、[ユニバーサルログイン](/docs/ja-jp/authenticate/login/auth0-universal-login)を使用しないと完了できません。
</Callout>

```swift lines theme={null}
Auth0
    .authentication()
    .login(usernameOrEmail: email, 
           password: password, 
           realmOrConnection: connection, 
           scope: scope)
    .start { result in
        switch result {
        case .success(let credentials): // ...
        case .failure(let error) where error.isVerificationRequired:
            DispatchQueue.main.async {
                Auth0
                    .webAuth()
                    .connection(connection)
                    .scope(scope)
                    .useEphemeralSession()
                    // ☝🏼 Otherwise a session cookie will remain
                    .parameters(["login_hint": email])
                    // ☝🏼 So the user doesn't have to type it again
                    .start { result in
                        // ...
                    }
            }
        case .failure(let error): // ...
        }
    }
```

サインアップの場合は、[別のパラメーター](/docs/ja-jp/authenticate/login/auth0-universal-login)を追加して、ユーザーをサインアップページに直接移動させることができます。

`.parameters(["login_hint": email, "screen_hint":"signup"])`

ユニバーサルログインをセットアップする方法については、「[Auth0.swiftを使ってみる](https://github.com/auth0/Auth0.swift#getting-started)」をお読みください。

### Auth0.Androidの例

アプリケーションが、Authentication APIを通じてデータベースログイン/サインアップを実行する場合は、`AuthenticationException#isVerificationRequired()`エラーを処理する必要があります。このエラーは、要求が疑わしいとフラグが立てられ、ユーザーのログインに別の検証ステップが必要であることを示します。

<Callout icon="file-lines" color="#0EA5E9" iconType="regular">
  この検証ステップはWebベースであるため、[ユニバーサルログイン](/docs/ja-jp/authenticate/login/auth0-universal-login)を使用しないと完了できません。
</Callout>

```javascript lines theme={null}
final String email = "username@domain.com";
final String password = "a secret password";
final String realm = "my-database-connection";

AuthenticationAPIClient authentication = new AuthenticationAPIClient(account);
authentication.login(email, password, realm)
        .start(new BaseCallback<Credentials, AuthenticationException>() {

            @Override
            public void onFailure(AuthenticationException error) {
                if (error.isVerificationRequired()){
                    Map<String, Object> params = new HashMap<>();
                    params.put("login_hint", email); // So the user doesn't have to type it again
                    WebAuthProvider.login(account)
                            .withConnection(realm)
                            .withParameters(params)
                            .start(LoginActivity.this, new AuthCallback() {
                                // You might already have an AuthCallback instance defined

                                @Override
                                public void onFailure(@NonNull Dialog dialog) {
                                    // Error dialog available
                                }

                                @Override
                                public void onFailure(AuthenticationException exception) {
                                    // Error
                                }

                                @Override
                                public void onSuccess(@NonNull Credentials credentials) {
                                    // Handle WebAuth success
                                }
                            });
                }
            }

            @Override
            public void onSuccess(Credentials payload) {
                // Handle API success
            }
        });
```

サインアップの場合は、[別のパラメーター](/docs/ja-jp/authenticate/login/auth0-universal-login)を追加して、ユーザーをサインアップページに直接移動させることができます。

`params.put("screen_hint", "signup");`

ユニバーサルログインをセットアップする方法については、「[ユニバーサルログインSDKによるAuth0.Androidの認証](https://github.com/auth0/Auth0.Android#authentication-with-universal-login)」ドキュメントをお読みください。

## Lock.SwiftとLock.Android

ユニバーサルログインを使用している場合、ボット検知は以下のSDKバージョンによって自動的にサポートされています。

* `Lock.Swift`バージョン2.19.0+
* `Lock.Android`バージョン2.22.0+

ユニバーサルログインを使用していない場合、ボット検知はサポートされていますが、アプリケーションを適宜構成する必要があります。

* アプリケーションは、`requires_verification`という例外（ログイン試行が高リスクであると判定されると例外をスローする）を処理し、CAPTCHA検証ステップを生じさせるためにWebAuthフローをトリガーする必要があります。
* WebAuthフローをトリガーしたら、ユーザーがユーザー名をもう一度入力する必要がないように、`login_hint`パラメーターを渡してください。

## Authentication API（認証API）

Authentication APIを直接使用している場合、ボット検知はサポートされていますが、アプリケーションを適宜構成する必要があります。

* アプリケーションは、`requires_verification`エラー（ログイン試行が高リスクであると判定されるとAuthentication APIによって返される）を処理し、CAPTCHA検証ステップを生じさせるためにWebAuthフローをトリガーする必要があります。

## もっと詳しく

* [ボット検知をカスタムログインページに追加する](/docs/ja-jp/secure/attack-protection/bot-detection/bot-detection-custom-login-pages)
