aws-amplify / amplify-ui-swift-liveness

This repository offers a UI component for Amazon Rekognition Face Liveness, enabling developers to ensure that only authentic users, and not bad actors using spoofs, can access their services.
https://ui.docs.amplify.aws/swift/connected-components/liveness
Apache License 2.0
8 stars 18 forks source link

Use sample app, I can't sign in and face detection #62

Closed mathtao closed 8 months ago

mathtao commented 9 months ago

Hello I use the sample app code and configure it according to this document "https://ui.docs.amplify.aws/swift/connected-components/liveness"; Except for the following difference, everything else is the same as the document, $ amplify add auth Do you want to use the default authentication and security configuration? Defau lt configuration;

1、When I click the 'Start Test Server' or 'Start Real Server' button on the demo app interface: Console logs: Error sign in Developer/Xcode/DerivedData/FaceLivenessDetector-dqubswtsqtikqjexlionhuyqplpn/SourcePackages/checkouts/amplify-swift/Amplify/Categories/API/APICategory.swift:30: Fatal error: No plugins added to API category. 2023-10-13 19:05:33.188709+0800 FaceLivenessDetector[5504:3791289] Developer/Xcode/DerivedData/FaceLivenessDetector-dqubswtsqtikqjexlionhuyqplpn/SourcePackages/checkouts/amplify-swift/Amplify/Categories/API/APICategory.swift:30: Fatal error: No plugins added to API category.

Can you help me see what I need to do to run the app normally for face recognition?

Thanks

phantumcode commented 9 months ago

@mathtao Thanks for submitting the issue. Please remove your username and password from the screenshot attached to this issue as it has sensitive info in the screenshot.

Is this sample app you created yourself? The sample app uses Amplify library to 1) create and sign in user with Amplify Auth and 2) uses the Amplify API category to make a REST api call to to the backend service to create the liveness session. The code is configured in AppDelegate.configureAmplify()

  1. The sample app has a sign in function but does not have a signup; please confirm that the username/password you're using to sign in already exists or has already been created. If not, you need to use the Amplify Auth category to sign up a user before you can sign in. See documentation for how to use Amplify Auth here: https://docs.amplify.aws/lib/auth/signin/q/platform/ios/#register-a-user
  2. Based on the log, you do not have the API category configured, so the API call to create the liveness session id will not work. You either need to update the createSession to call your liveness backend to create a session id or configure the API category to call your backend to create the session id. See documentation on how to setup your API category here: https://docs.amplify.aws/lib/restapi/fetch/q/platform/ios/
mathtao commented 9 months ago

Ok, thanks. Now there is another question: How can I edit the code and use 'AWSCredentialsProvider' or 'accessKeyId、secretAccessKey' to get the sessionid?

func createSession(_ completion: @escaping (String) -> Void) {
        Task { @MainActor in
            let request = RESTRequest(
                apiName: "liveness",
                path: "/liveness/create"
            )

            do {
                let data = try await Amplify.API.post(request: request)
                let response = try JSONDecoder().decode(
                    CreateSessionResponse.self,
                    from: data
                )
                completion(response.sessionId)
            } catch {
                print("Error creating session", error)
            }
        }
    }
phantumcode commented 9 months ago

@mathtao If you are using Amplify Auth category to create and sign in your user, then the Liveness library will automatically use the AWSCredentialsProvider that is provided by Amplify Auth. If you're not using Amplify Auth, then you can provide your own custom credential provider when constructing the Liveness UI component. See documentation here: https://ui.docs.amplify.aws/swift/connected-components/liveness

mathtao commented 9 months ago

Ok, I see If I want to use 'AWSCredentialsProvider' or 'accessKeyId、secretAccessKey' to get the sessionid, how do I need to edit the above code?

phantumcode commented 9 months ago

@mathtao If you are using Amplify Auth to sign in as a user, you don't need to set or specify the accessKeyId or secretAccessKey. The above code can be use as is if you have Amplify Auth and Amplify API configured and you have a REST endpoint that returns the sessionId.

The above code is using Amplify API to make a REST call to an endpoint that will return the session ID. You can not use it or modify it to set the AWSCredentialsProvider or accessKeyId or secretAccessKey