---
# Amplify UI Liveness Sample App
Amplify UI FaceLivenessDetector provides a UI component for Amazon Rekognition Face Liveness that helps developers verify that only real users, not bad actors using spoofs, can access your services.
More information on setting up and using the FaceLivenessDetector is in the [Amplify UI Face Liveness documentation](https://ui.docs.amplify.aws/swift/connected-components/liveness).
## Running the App
Prerequisite: The host app requires backend resources to be configured with Amplify Auth category for authentication and Amplify API for starting/creating Liveness sessions.
1. Install Xcode version 12.0 or higher
2. clone the Amplify UI Swift Liveness repository:
```
git clone https://github.com/aws-amplify/amplify-ui-swift-liveness.git
```
3. Change directory to `HostApp`
```
cd amplify-ui-swift-livenes/HostApp
```
4. Open HostApp.xcodeproj in Xcode
5. The sample app depends on a real device camera to capture videos. Build and deploy the app onto a real device.
6. When the app is launch, click the Sign in button to sign up and then sign in.
7. Once signed in and authenticated, the "Create Liveness Session" is enabled. Click the button to generate and get a session id from your backend.
8. Once a session id is created, the Liveness Check screen is displayed. Follow the instructions and click on Begin Check button to begin liveness verification.
## Provision AWS Backend Resources
1. Follow the [instructions](https://docs.amplify.aws/start/getting-started/installation/q/integration/ios/) to sign up for an AWS account and set up the Amplify CLI.
2. Initialize Amplify in the project by running the following command from the project directory:
```
amplify init
```
Provide the responses shown after each of the following prompts.
```
? Enter a name for the project: `LivenessHostApp`
The following configuration will be applied:
Project information
| Name: LivenessHostApp
| Environment: dev
| Default editor: Visual Studio Code
| App type: ios
? Initialize the project with the above configuration? No
? Enter a name for the environment: `dev`
? Choose your default editor: `Xcode (macOS only)`
? Choose the type of app that you're building: `ios`
? Select the authentication method you want to use:
`AWS profile`
? Please choose the profile you want to use
`default`
```
Wait until provisioning is finished. Upon successfully running `amplify init`, you will see a configuration file created called `amplifyconfiguration.json`. This file will be bundled into your application so that the Amplify libraries know how to reach your provisioned backend resources at runtime. You can verify by checking that the file is included in the `Copy Bundle Resources` Build Phases for the `HostApp` target in Xcode.
3. Configure Auth Category
The Amplify Auth category provides an interface for authenticating a user and also provides the necessary authorization to other Amplify categories. It comes with default, built-in support for Amazon Cognito User Pools and Identity Pools. From your project directory, run the following command to add the Amplify Auth category:
```
amplify add auth
```
Provide the responses shown after each of the following prompts.
```
? Do you want to use the default authentication and security configuration?
`Default configuration with Social Provider (Federation)`
? How do you want users to be able to sign in?
`Username`
? Do you want to configure advanced settings?
`No, I am done.`
? What domain name prefix you want us to create for you?
`(default)`
? Enter your redirect signin URI:
`myapp://`
? Do you want to add another redirect signin URI
`No`
? Enter your redirect signout URI:
`myapp://`
? Do you want to add another redirect signout URI
`No`
? Select the social providers you want to configure for your user pool:
``
```
4. Once finished, run `amplify push` to publish your changes.
Upon completion, `amplifyconfiguration.json` should be updated to reference these provisioned backend resources.
5. Follow the steps below to create an inline policy to enable authenticated app users to access Rekognition, which powers the FaceLivenessDetector.
1. Go to AWS IAM console, then Roles
2. Select the newly created `authRole` for the project (`amplify----authRole`).
3. Choose **Add Permissions**, then select **Create Inline Policy**, then choose **JSON** and paste the following:
```
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "rekognition:StartFaceLivenessSession",
"Resource": "*"
}
]
}
```
4. Choose **Review Policy**
5. Name the policy
6. Choose **Create Policy**
6. Set up a backend to create the liveness session and retrieve the liveness session results. The liveness sample app is set up to use API Gateway endpoints for creating and retrieving the liveness session. Follow the [Amazon Rekognition Liveness guide](https://docs.aws.amazon.com/rekognition/latest/dg/face-liveness-programming-api.html) to set up your backend.
1. Edit the [StartSessionViewModel.swift](https://github.com/aws-amplify/amplify-ui-swift-liveness/blob/main/HostApp/HostApp/Views/StartSessionViewModel.swift) in your project as necessary to generate the session id from your backend.
2. Edit the [ExampleLivenessViewModel.swift](https://github.com/aws-amplify/amplify-ui-swift-liveness/blob/main/HostApp/HostApp/Views/ExampleLivenessViewModel.swift) in your project as necessary to get the liveness result from your backend.