diff --git a/.gitignore b/.gitignore index 3b298120..df4f2021 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,18 @@ DerivedData/ .swiftpm/config/registries.json .swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata .netrc +HostApp/amplify/ +HostApp/build/ +HostApp/dist/ +HostApp/node_modules/ +HostApp/generated-src/ +HostApp/aws-exports.js +HostApp/.gitignore +HostApp/awsconfiguration.json +HostApp/amplifyconfiguration.json +HostApp/amplifyconfiguration.dart +HostApp/amplify-build-config.json +HostApp/amplify-gradle-config.json +HostApp/amplifytools.xcconfig +HostApp/.secret-* +HostApp/**.sample \ No newline at end of file diff --git a/HostApp/README.md b/HostApp/README.md index fdbef9d8..e78c4ed1 100644 --- a/HostApp/README.md +++ b/HostApp/README.md @@ -8,31 +8,108 @@ Amplify UI FaceLivenessDetector provides a UI component for Amazon Rekognition F 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). -## Set Up +## Running the App -This sample app depends on AWS Amplify library and assumes Amplify Auth and Amplify API are configured. You will need to either update the `amplifyconfiguration.json` with the missing configuration details or replace the placeholder file wit your `amplifyconfiguration.json` file. For additional details on configuring Amplify, see [Face Liveness documentation](https://ui.docs.amplify.aws/swift/connected-components/liveness#step-1-configure-amplify) +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. -To update the `amplifyconfiguration.json`: -Edit the file with the appropriate credential provider Pool ID and Region. +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 ``` -"Default": { - "PoolId": "us-east-1:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", - "Region": "us-east-1" -} +Provide the responses shown after each of the following prompts. ``` +? Enter a name for the project: `LivenessHostApp` +The following configuration will be applied: -This sample app assumes that the session id is fetched from an API REST endpoint, update the Amplify API Category section of the `amplifyconfiguration.json` file with the appropriate configuration for your REST API endpoint +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` ``` -"awsAPIPlugin": { - "liveness": { - "endpointType": "REST", - "endpoint": "https://xxxxxxxxxx.execute-api.us-east-1.amazonaws.com/xxxx", - "region": "us-east-1", - "authorizationType": "AWS_IAM" - } -} +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** -## Running Sample App -The sample app depends on a real device camera to capture videos. Open the sample app in Xcode and deploy the app onto a real device. +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. \ No newline at end of file