> ## Documentation Index
> Fetch the complete documentation index at: https://docs.median.co/llms.txt
> Use this file to discover all available pages before exploring further.

# Android biometric

> Authenticate Android users with fingerprint or face unlock by saving and retrieving an encrypted secret with the JavaScript Bridge.

Securely authenticate users on Android devices using fingerprint, facial recognition, or other biometric methods with the Median Android Biometric Authentication plugin. This plugin uses the Median JavaScript Bridge to store and retrieve encrypted secrets, enabling biometric sign-in.

The plugin supports both:

* **Strong biometrics**: Fingerprint sensors, infrared facial recognition (hardware-backed)
* **Weak biometrics**: Face unlock via standard camera (software-only)

As the developer, you define the minimum biometric level required (strong or weak) depending on your app’s security needs.

## How it works

1. **Check biometric availability:** First, check whether biometric authentication data is available and biometrics are supported for the device (older models or MDM configurations may disable the support).
2. **Save sign-in secret:** After a user signs in and biometric authentication is available, the website can save a secret using the plugin. The secret is stored using cryptographic hardware to ensure it cannot be retrieved without biometric authentication. Saving the secret does not require user interaction.
3. **Retrieve saved secret:** On future visits, if a saved secret is available, the site can prompt the user to authenticate via Android Biometrics. If authentication succeeds, the secret is returned via the JavaScript callback. If it fails, an error is returned.
4. **Use secret to sign in:** Once the secret is recovered, you can either use it to sign in the user directly or populate the login form on your web app.

> [!TIP]
>
> **Developer Demo**
>
> Display our demo page in your app with the Face ID / Touch ID Android Biometric Native Plugin active to test during development [https://median.dev/auth/](https://median.dev/auth/)

## Implementation guide

This guide assumes a working publicly-accessible website (or test site) with a username and password login system.

### Saving a secret after login

After a user successfully signs in to your website with their username and password, check whether the device has biometric capabilities available. If biometrics are available, save a secret for future retrieval. The secret must be a single string, and can be a combination of the username and password or an authentication token. You may specify a minimum biometric level to support, either `strong` or `weak`.

For example, you may embed this JavaScript into your post-login page:

Median JavaScript Bridge

```javascript JavaScript theme={null}
var username = 'andy';
var password = 'password';

median.auth.status({'callbackFunction': median_status_afterlogin}); // returns promise

function median_status_afterlogin(data) {
  if (data && data.hasTouchId) {
    var secret = JSON.stringify({
      username: username,
      password: password
    });

    median.auth.save({
      'secret': secret,
      'minimumAndroidBiometric': 'strong'
    });
  }
}
```

**Tip:** Some JavaScript Bridge commands return promises. They are usually declared as such through a comment to help you identify them. Learn more about [promises in the JavaScript Bridge](https://docs.median.co/docs/javascript-bridge.md#promises).

In this example, we have saved the username and password as the secret. You may choose to save an authentication token instead. We have specified the `minimumAndroidBiometric` as `strong` which is the default biometric level.

### Checking for a saved secret on login page

On the login page, you will need to know whether or not to prompt for biometric sign-in. Start by getting the status:

Median JavaScript Bridge

```javascript JavaScript theme={null}
median.auth.status({'callbackFunction': median_status_beforelogin}); // returns promise

function median_status_beforelogin(data) {
   if (data && data.hasTouchId && data.hasSecret) {
       // Prompt the user to use biometrics to sign in
       median.auth.get({'callbackFunction': median_secret_callback});
   }
}

function median_secret_callback(data) {
    if (data && data.success && data.secret) {
        var credentials = JSON.parse(data.secret);
        var username = credentials.username;
        var password = credentials.password;

        // Use username and password to sign in here,
        // e.g. an http post or ajax request
    } else {
        // Allow manual entry
    }
}
```

Once the `median_secret_callback` function is called with the previously saved secret, it should perform a request to sign in the user. If the credentials are incorrect, you should delete the secret and allow manual sign-in by running the function:

Median JavaScript Bridge

```javascript JavaScript theme={null}
// delete secret if credentials are incorrect
median.auth.delete({'callbackFunction': CALLBACK});
```

## Median JavaScript Bridge reference

### Check biometric availability

Run the JavaScript function:

Median JavaScript Bridge

```javascript JavaScript theme={null}
median.auth.status({
  'minimumAndroidBiometric': 'strong', // optional: 'strong' or 'weak', default is 'strong'
  'callbackFunction': CALLBACK // optional if callback is used rather than promise
});
```

The app will return a promise, or if provided execute CALLBACK, with an object parameter containing the fields:

* `hasTouchId`: `true` or `false`. Set to `true` on Android devices with fingerprints enrolled.
* `hasSecret`: `true` or `false`

### Save a secret

Typically you will want to first check that biometrics are available via the status function above and then save the secret.

Run the JavaScript function:

Median JavaScript Bridge

```javascript JavaScript theme={null}
median.auth.save({
  'secret': secret,
  'minimumAndroidBiometric': 'strong', // optional: 'strong' or 'weak', default is 'strong'
  'callbackFunction': CALLBACK // optional if callback is used rather than promise
});
```

The app will return a promise, or if provided execute CALLBACK, with an object with a `success` field.

### Retrieving a secret

Run the JavaScript function:

Median JavaScript Bridge

```javascript JavaScript theme={null}
median.auth.get({
  'callbackFunction': CALLBACK, // optional if callback is used rather than promise
  'minimumAndroidBiometric': 'strong', // optional: 'strong' or 'weak', default is 'strong'
  'prompt': 'PROMPT',
  'callbackOnCancel': 1 // optional: 1 or 0
});
```

**Prompt is only available for iOS and it has been included above to ensure cross-platform compatibility.**

The app will return a promise, or if provided execute CALLBACK, with an object parameter containing the fields:

* `success`: true or false
* `error`: provided success is false (see error codes below)
* `secret`: the previously stored secret
* `callbackOnCancel` is optional. If set to `1` and a `callbackFunction` has been provided, when the user cancels the authentication the callback function will be invoked with `success=false`, `error=userCanceled`. If `callbackOnCancel` is not set (or set to 0), the callback will not be run on cancel.

### Delete a secret

Run the JavaScript function:

Median JavaScript Bridge

```javascript JavaScript theme={null}
median.auth.delete({
  'callbackFunction': CALLBACK // optional if callback is used rather than promise
});
```

The app will return a promise, or if provided execute CALLBACK, with an object parameter containing the fields:

* `success`: true or false
* `error`: provided if success is false

### Possible error values

In general, you will only need to handle `authenticationFailed` in the "get secret" request.

* `duplicateItem`: Secret already exists
* `itemNotFound`: No secret saved
* `authenticationFailed`: Biometric check failed
* `genericError`: Unexpected failure
* `userCanceled`: User canceled the auth prompt
* `unimplemented`: Plugin not supported

## Testing Android biometric integration

We recommend testing on physical devices to confirm the flow is working as expected for devices with Android Biometric support, as well as older models or more restricted device configurations.

Additionally, you can also test the integration using the Appetize Simulators.

1. Open the demo page in the simulator
2. Click the Fingerprint ID Button (as shown below) to enable biometrics support in the simulator
3. Sign in with credentials
4. Return to the demo page and use the Login with Biometrics button without having to provide username and password again

![Fingerprint ID button in the Appetize simulator toolbar](https://mintcdn.com/median-co/7LCOHMhgIef7ewYE/images/docs/7101a4a47217df84be067110782a1ef0df1addbd7f0a3c45375744283a9cd22a-Screenshot_2025-07-15_at_11.53.31.png?fit=max\&auto=format\&n=7LCOHMhgIef7ewYE\&q=85\&s=be9f766b260dea653f6a1552fe27310c)

Appetize: Fingerprint ID button

## Whitelist domains for plugin access

By default, any page loaded in your app will be able to use Median JavaScript Bridge to retrieve secrets. If you are allowing any domains you do not control to be loaded within your app (see [Link Handling](https://docs.median.co/docs/link-handling-overview.md)), we strongly recommend whitelisting only certain domains.

To do so, go to the **Native Plugins** tab in App Studio, click **Settings** for the Face ID/TouchID Android Biometrics plugin and add your whitelisted URLs as shown below.

Regular expressions are supported to allow wildcards in the URL.

![Whitelisted URLs in the biometric plugin settings](https://mintcdn.com/median-co/7LCOHMhgIef7ewYE/images/docs/6ac6443f60d854e11d699edae7fa95c860c78b958e13862a4ce17e14151161c2-Screenshot_2025-07-15_at_11.32.35.png?fit=max\&auto=format\&n=7LCOHMhgIef7ewYE\&q=85\&s=891e2e9c7f9d8899ca88869eb1f387e6)

Whitelisting URLs for access


## Related topics

- [Face ID, Touch ID, and Android biometrics](https://docs.median.co/docs/auth.md)
- [Salesforce LWC component deployment and reference](https://docs.median.co/docs/salesforce-lwc-components.md)
- [Auth0](https://docs.median.co/docs/auth0.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.