diff --git a/.gitignore b/.gitignore index c5a07310..f9d33fdd 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ .DS_Store /.build +/.index-build /Packages /*.xcodeproj xcuserdata/ diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 00000000..0a8642fa --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,10 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml +# Zeppelin ignored files +/ZeppelinRemoteNotebooks/ diff --git a/.idea/amplify-ui-swift-liveness.iml b/.idea/amplify-ui-swift-liveness.iml new file mode 100644 index 00000000..d6ebd480 --- /dev/null +++ b/.idea/amplify-ui-swift-liveness.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml new file mode 100644 index 00000000..919ce1f1 --- /dev/null +++ b/.idea/codeStyles/Project.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml new file mode 100644 index 00000000..a55e7a17 --- /dev/null +++ b/.idea/codeStyles/codeStyleConfig.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 00000000..1ec64b08 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 00000000..b1003417 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 00000000..35eb1ddf --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/AmplifyUILiveness.podspec b/AmplifyUILiveness.podspec new file mode 100644 index 00000000..09e78d6a --- /dev/null +++ b/AmplifyUILiveness.podspec @@ -0,0 +1,12 @@ +Pod::Spec.new do |s| + s.name = 'AmplifyUILiveness' + s.version = '1.0.0' + s.summary = 'AWS Amplify UI Liveness module' + s.homepage = 'https://github.com/aws-amplify/amplify-ui-swift-liveness' + s.license = { :type => 'Apache 2.0', :file => 'LICENSE' } + s.author = { 'AWS Amplify' => 'aws-amplify@amazon.com' } + s.source = { :git => 'https://github.com/aws-amplify/amplify-ui-swift-liveness.git', :branch => 'main' } + s.ios.deployment_target = '13.0' + s.source_files = 'Sources/**/*.{swift,h,m}' + s.swift_version = '5.0' +end \ No newline at end of file diff --git a/HostApp/.gitignore b/HostApp/.gitignore new file mode 100644 index 00000000..f54d96e8 --- /dev/null +++ b/HostApp/.gitignore @@ -0,0 +1,21 @@ +#amplify-do-not-edit-begin +amplify/\#current-cloud-backend +amplify/.config/local-* +amplify/logs +amplify/mock-data +amplify/mock-api-resources +amplify/backend/amplify-meta.json +amplify/backend/.temp +build/ +dist/ +node_modules/ +aws-exports.js +awsconfiguration.json +amplifyconfiguration.json +amplifyconfiguration.dart +amplify-build-config.json +amplify-gradle-config.json +amplifytools.xcconfig +.secret-* +**.sample +#amplify-do-not-edit-end \ No newline at end of file diff --git a/HostApp/HostApp.xcodeproj/project.pbxproj b/HostApp/HostApp.xcodeproj/project.pbxproj index 7d1314c5..b39fb77e 100644 --- a/HostApp/HostApp.xcodeproj/project.pbxproj +++ b/HostApp/HostApp.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + 87BCB9652D67C0A40055559D /* CredsProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 87BCB9642D67C09D0055559D /* CredsProvider.swift */; }; 90236C77299D6D41009FD1A7 /* HostAppApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 90236C76299D6D40009FD1A7 /* HostAppApp.swift */; }; 90493F822992D64000CFE674 /* LivenessResult.swift in Sources */ = {isa = PBXBuildFile; fileRef = 90493F812992D64000CFE674 /* LivenessResult.swift */; }; 904CC73D2996E650002E0753 /* RootView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 904CC73C2996E650002E0753 /* RootView.swift */; }; @@ -54,6 +55,7 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ + 87BCB9642D67C09D0055559D /* CredsProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CredsProvider.swift; sourceTree = ""; }; 900129D4298ACA9100AE3524 /* HostApp.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = HostApp.entitlements; sourceTree = ""; }; 90236C76299D6D40009FD1A7 /* HostAppApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HostAppApp.swift; sourceTree = ""; }; 90493F812992D64000CFE674 /* LivenessResult.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LivenessResult.swift; sourceTree = ""; }; @@ -131,6 +133,7 @@ 9070FFBD285112B5009867D5 /* HostAppUITests */, 9070FFA1285112B4009867D5 /* Products */, 90215EED291E9FB60050F2AD /* Frameworks */, + A5A9AF5054D0FF13505B212A /* AmplifyConfig */, ); sourceTree = ""; }; @@ -179,6 +182,7 @@ 909308C8297DC4CA00F3CC6E /* Views */ = { isa = PBXGroup; children = ( + 87BCB9642D67C09D0055559D /* CredsProvider.swift */, 904CC73C2996E650002E0753 /* RootView.swift */, 906AB82329E9F48C007FFC81 /* StartSessionView.swift */, 906AB82B29EA0BFD007FFC81 /* StartSessionViewModel.swift */, @@ -213,6 +217,13 @@ path = Model; sourceTree = ""; }; + A5A9AF5054D0FF13505B212A /* AmplifyConfig */ = { + isa = PBXGroup; + children = ( + ); + name = AmplifyConfig; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -307,6 +318,9 @@ Base, ); mainGroup = 9070FF97285112B4009867D5; + packageReferences = ( + 8704823D2D6CE3FE00DF249F /* XCRemoteSwiftPackageReference "amplify-ui-swift-liveness" */, + ); productRefGroup = 9070FFA1285112B4009867D5 /* Products */; projectDirPath = ""; projectRoot = ""; @@ -353,6 +367,7 @@ files = ( 906AB82829EA04B5007FFC81 /* ExampleLivenessViewModel.swift in Sources */, 906AB83029EA0DC5007FFC81 /* LivenessResultContentView+Result.swift in Sources */, + 87BCB9652D67C0A40055559D /* CredsProvider.swift in Sources */, 909308CD297DC4E700F3CC6E /* UIColor+Hex.swift in Sources */, 90493F822992D64000CFE674 /* LivenessResult.swift in Sources */, 906AB82229E9F432007FFC81 /* View+Background.swift in Sources */, @@ -526,7 +541,7 @@ CODE_SIGN_STYLE = Automatic; CURRENT_PROJECT_VERSION = 1; DEVELOPMENT_ASSET_PATHS = "\"HostApp/Preview Content\""; - DEVELOPMENT_TEAM = W3DRXD72QU; + DEVELOPMENT_TEAM = RP2SA7L4ZN; ENABLE_PREVIEWS = YES; GENERATE_INFOPLIST_FILE = YES; INFOPLIST_FILE = HostApp/Info.plist; @@ -560,7 +575,7 @@ CODE_SIGN_STYLE = Automatic; CURRENT_PROJECT_VERSION = 1; DEVELOPMENT_ASSET_PATHS = "\"HostApp/Preview Content\""; - DEVELOPMENT_TEAM = W3DRXD72QU; + DEVELOPMENT_TEAM = RP2SA7L4ZN; ENABLE_PREVIEWS = YES; GENERATE_INFOPLIST_FILE = YES; INFOPLIST_FILE = HostApp/Info.plist; @@ -701,6 +716,17 @@ }; /* End XCConfigurationList section */ +/* Begin XCRemoteSwiftPackageReference section */ + 8704823D2D6CE3FE00DF249F /* XCRemoteSwiftPackageReference "amplify-ui-swift-liveness" */ = { + isa = XCRemoteSwiftPackageReference; + repositoryURL = "https://github.com/aws-amplify/amplify-ui-swift-liveness"; + requirement = { + kind = upToNextMajorVersion; + minimumVersion = 1.3.4; + }; + }; +/* End XCRemoteSwiftPackageReference section */ + /* Begin XCSwiftPackageProductDependency section */ 973619212BA378200003A590 /* FaceLiveness */ = { isa = XCSwiftPackageProductDependency; diff --git a/HostApp/HostApp.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/HostApp/HostApp.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index 9a475d8f..d736e668 100644 --- a/HostApp/HostApp.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/HostApp/HostApp.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -5,8 +5,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/aws-amplify/amplify-swift", "state" : { - "revision" : "5b603ff7cfe1b03d753ae7ff9664316e6447f0ae", - "version" : "2.46.1" + "revision" : "7b1d5ee05a23ea24c7458dffed1c563c8501042d", + "version" : "2.45.4" } }, { @@ -23,17 +23,17 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/awslabs/aws-crt-swift", "state" : { - "revision" : "dd17a98750b6182edacd6e8f0c30aa289c472b22", - "version" : "0.40.0" + "revision" : "3f844bef042cc0a4c3381f7090414ce3f9a7e935", + "version" : "0.37.0" } }, { "identity" : "aws-sdk-swift", "kind" : "remoteSourceControl", - "location" : "https://github.com/awslabs/aws-sdk-swift.git", + "location" : "https://github.com/awslabs/aws-sdk-swift", "state" : { - "revision" : "9ad12684f6cb9c9b60e840c051a2bba604024650", - "version" : "1.0.69" + "revision" : "c6c1064da9bfccb119a7a8ab9ba636fb3bbfa6f5", + "version" : "1.0.47" } }, { @@ -41,8 +41,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/smithy-lang/smithy-swift", "state" : { - "revision" : "402f091374dcf72c1e7ed43af10e3ee7e634fad8", - "version" : "0.106.0" + "revision" : "3cd9f181b3ba8ff71da43bf53c09f8de6790a4ad", + "version" : "0.96.0" } }, { @@ -59,8 +59,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/apple/swift-log.git", "state" : { - "revision" : "3d8596ed08bd13520157f0355e35caed215ffbfa", - "version" : "1.6.3" + "revision" : "96a2f8a0fa41e9e09af4585e2724c4e825410b91", + "version" : "1.6.2" } } ], diff --git a/HostApp/HostApp/HostAppApp.swift b/HostApp/HostApp/HostAppApp.swift index 61863c5c..9a96d9f0 100644 --- a/HostApp/HostApp/HostAppApp.swift +++ b/HostApp/HostApp/HostAppApp.swift @@ -31,7 +31,7 @@ struct HostAppApp: App { let auth = AWSCognitoAuthPlugin() let api = AWSAPIPlugin() try Amplify.add(plugin: auth) - try Amplify.add(plugin: api) + //try Amplify.add(plugin: api) try Amplify.configure() } catch { print("Error configuring Amplify", error) diff --git a/HostApp/HostApp/Views/CredsProvider.swift b/HostApp/HostApp/Views/CredsProvider.swift new file mode 100644 index 00000000..8c33e1ad --- /dev/null +++ b/HostApp/HostApp/Views/CredsProvider.swift @@ -0,0 +1,22 @@ +// +// CredsProvider.swift +// HostApp +// +// Created by victor julio on 20/02/25. +// + +//import Amplify +//import AWSPluginsCore +//import AwsCommonRuntimeKit +// +// +//struct CredsProvider: AWSCredentialsProvider { +// func fetchAWSCredentials() async throws -> AWSCredentials { +// // Fetch the credentials +// let provider = try CredentialsProvider(source: .static(accessKey: accessKey, +// secret: secret, +// sessionToken: sessionToken)) +// return provider +// +// } +//} diff --git a/HostApp/HostApp/Views/ExampleLivenessViewModel.swift b/HostApp/HostApp/Views/ExampleLivenessViewModel.swift index a04571bc..2650e07d 100644 --- a/HostApp/HostApp/Views/ExampleLivenessViewModel.swift +++ b/HostApp/HostApp/Views/ExampleLivenessViewModel.swift @@ -18,14 +18,21 @@ class ExampleLivenessViewModel: ObservableObject { } func fetchLivenessResult() async throws -> LivenessResultContentView.Result { - let request = RESTRequest( - apiName: "liveness", - path: "/liveness/\(sessionID)" - ) - - let data = try await Amplify.API.get(request: request) - let result = try JSONDecoder().decode(LivenessResult.self, from: data) - let score = LivenessResultContentView.Result(livenessResult: result) + guard let url = URL(string: "https://c18b-181-236-137-100.ngrok-free.app/liveness/result/\(sessionID)") else { + throw URLError(.badURL) + } + + // Configura la petición GET + var request = URLRequest(url: url) + request.httpMethod = "GET" + request.setValue("application/json", forHTTPHeaderField: "Content-Type") + + // Realiza la llamada asíncrona al endpoint + let (data, _) = try await URLSession.shared.data(for: request) + + // Decodifica la respuesta en el modelo LivenessResultContentView.Result + let livenessResult = try JSONDecoder().decode(LivenessResult.self, from: data) + let score = LivenessResultContentView.Result(livenessResult: livenessResult) return score } diff --git a/HostApp/HostApp/Views/StartSessionView.swift b/HostApp/HostApp/Views/StartSessionView.swift index 42f64401..a3a7c2f5 100644 --- a/HostApp/HostApp/Views/StartSessionView.swift +++ b/HostApp/HostApp/Views/StartSessionView.swift @@ -41,7 +41,7 @@ struct StartSessionView: View { showAlert = err != nil } }, - enabled: viewModel.isSignedIn + enabled: true ) .alert(isPresented: $showAlert) { Alert( diff --git a/HostApp/HostApp/Views/StartSessionViewModel.swift b/HostApp/HostApp/Views/StartSessionViewModel.swift index 8b8484db..dc2b2ad3 100644 --- a/HostApp/HostApp/Views/StartSessionViewModel.swift +++ b/HostApp/HostApp/Views/StartSessionViewModel.swift @@ -7,6 +7,7 @@ import SwiftUI import Amplify +import Foundation class StartSessionViewModel: ObservableObject { @Published var presentationState: StartSessionView.PresentationState = .loading @@ -21,6 +22,9 @@ class StartSessionViewModel: ObservableObject { presentationState = .loading do { let session = try await Amplify.Auth.fetchAuthSession() + //print("the session") + //print(session) + //print("okok") presentationState = session.isSignedIn ? .signedIn(action: signOut) : .signedOut(action: signIn) @@ -31,27 +35,44 @@ class StartSessionViewModel: ObservableObject { } } + + struct StartResponse: Codable { + let sid: String + } func createSession(_ completion: @escaping (String?, Error?) -> Void) { Task { @MainActor in let currentPresentationState = presentationState presentationState = .loading - 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 - ) + // Configura la URL y la petición + guard let url = URL(string: "https://c18b-181-236-137-100.ngrok-free.app/liveness/start") else { + throw URLError(.badURL) + } + + var request = URLRequest(url: url) + request.httpMethod = "POST" + request.setValue("application/json", forHTTPHeaderField: "Content-Type") + + // Si necesitas enviar un body (en este ejemplo se envía un JSON vacío) + let body: [String: Any] = [:] + request.httpBody = try? JSONSerialization.data(withJSONObject: body) + + // Realiza la llamada asíncrona al API + let (data, _) = try await URLSession.shared.data(for: request) + + // Decodifica la respuesta JSON y extrae el sId + let decoder = JSONDecoder() + let startResponse = try decoder.decode(StartResponse.self, from: data) + print("respone: \(startResponse)") + let sessionId = startResponse.sid + presentationState = currentPresentationState - completion(response.sessionId, nil) + completion(sessionId, nil) } catch { presentationState = currentPresentationState - print("Error creating session", error) + print("Error creating session:", error) completion(nil, error) } } diff --git a/Package.resolved b/Package.resolved index e4e6e13c..d736e668 100644 --- a/Package.resolved +++ b/Package.resolved @@ -5,8 +5,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/aws-amplify/amplify-swift", "state" : { - "revision" : "5b603ff7cfe1b03d753ae7ff9664316e6447f0ae", - "version" : "2.46.1" + "revision" : "7b1d5ee05a23ea24c7458dffed1c563c8501042d", + "version" : "2.45.4" } }, { @@ -23,8 +23,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/awslabs/aws-crt-swift", "state" : { - "revision" : "dd17a98750b6182edacd6e8f0c30aa289c472b22", - "version" : "0.40.0" + "revision" : "3f844bef042cc0a4c3381f7090414ce3f9a7e935", + "version" : "0.37.0" } }, { @@ -32,8 +32,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/awslabs/aws-sdk-swift", "state" : { - "revision" : "9ad12684f6cb9c9b60e840c051a2bba604024650", - "version" : "1.0.69" + "revision" : "c6c1064da9bfccb119a7a8ab9ba636fb3bbfa6f5", + "version" : "1.0.47" } }, { @@ -41,8 +41,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/smithy-lang/smithy-swift", "state" : { - "revision" : "402f091374dcf72c1e7ed43af10e3ee7e634fad8", - "version" : "0.106.0" + "revision" : "3cd9f181b3ba8ff71da43bf53c09f8de6790a4ad", + "version" : "0.96.0" } }, { @@ -59,8 +59,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/apple/swift-log.git", "state" : { - "revision" : "3d8596ed08bd13520157f0355e35caed215ffbfa", - "version" : "1.6.3" + "revision" : "96a2f8a0fa41e9e09af4585e2724c4e825410b91", + "version" : "1.6.2" } } ], diff --git a/Package.swift b/Package.swift index 4e2d2e80..a302e437 100644 --- a/Package.swift +++ b/Package.swift @@ -13,7 +13,7 @@ let package = Package( targets: ["FaceLiveness"]), ], dependencies: [ - .package(url: "https://github.com/aws-amplify/amplify-swift", exact: "2.46.1") + .package(url: "https://github.com/aws-amplify/amplify-swift", exact: "2.45.4") ], targets: [ .target( diff --git a/Sources/FaceLiveness/Utilities/Color+Liveness.swift b/Sources/FaceLiveness/Utilities/Color+Liveness.swift index 6d998b58..884deb4c 100644 --- a/Sources/FaceLiveness/Utilities/Color+Liveness.swift +++ b/Sources/FaceLiveness/Utilities/Color+Liveness.swift @@ -9,13 +9,13 @@ import SwiftUI extension Color { static let livenessPrimaryBackground = Color.dynamicColors( - light: .hex("#047D95"), - dark: .hex("#7DD6E8") + light: .hex("#FF8473"), + dark: .hex("#FF8473") ) static let livenessPrimaryLabel = Color.dynamicColors( light: .white, - dark: .hex("#0D1926") + dark: .white ) static let livenessBackground = Color.dynamicColors( @@ -44,8 +44,8 @@ extension Color { ) static let livenessWarningLabel = Color.dynamicColors( - light: .hex("#002266"), - dark: .hex("#EFBF8F") + light: .hex("#FFFFFF"), + dark: .hex("#FFFFFF") ) static let livenessPreviewBorder = Color.dynamicColors( diff --git a/Sources/FaceLiveness/Utilities/UserAgent.swift b/Sources/FaceLiveness/Utilities/UserAgent.swift index 6184f428..2451a93c 100644 --- a/Sources/FaceLiveness/Utilities/UserAgent.swift +++ b/Sources/FaceLiveness/Utilities/UserAgent.swift @@ -10,7 +10,7 @@ import InternalAmplifyCredentials struct UserAgentValues { - static let libVersion = "1.3.5" + static let libVersion = "1.3.4" static let libName = "amplify-ui-swift-face-liveness" let amplifyVersion: String diff --git a/Sources/FaceLiveness/Views/GetReadyPage/GetReadyPageView.swift b/Sources/FaceLiveness/Views/GetReadyPage/GetReadyPageView.swift index 00ecb9b7..e5641c2b 100644 --- a/Sources/FaceLiveness/Views/GetReadyPage/GetReadyPageView.swift +++ b/Sources/FaceLiveness/Views/GetReadyPage/GetReadyPageView.swift @@ -25,6 +25,7 @@ struct GetReadyPageView: View { CameraPreviewView() VStack { WarningBox( + titleText: LocalizedStrings.get_ready_photosensitivity_title, bodyText: LocalizedStrings.get_ready_photosensitivity_description, popoverContent: { photosensitivityWarningPopoverContent } @@ -51,7 +52,7 @@ struct GetReadyPageView: View { ) .disabled(beginCheckButtonDisabled) .frame(height: 52) - ._background { Color.livenessPrimaryBackground } + ._background {Color(UIColor.hex("#FF8473")) } .cornerRadius(14) .padding([.leading, .trailing]) .padding(.bottom, 16) @@ -60,6 +61,7 @@ struct GetReadyPageView: View { private var photosensitivityWarningPopoverContent: some View { VStack { Text(LocalizedStrings.get_ready_photosensitivity_dialog_title) + .background(Color.yellow) .font(.system(size: 20, weight: .medium)) .frame(alignment: .center) .padding() diff --git a/Sources/FaceLiveness/Views/WarningBox.swift b/Sources/FaceLiveness/Views/WarningBox.swift index 050c2aa4..8cf89319 100644 --- a/Sources/FaceLiveness/Views/WarningBox.swift +++ b/Sources/FaceLiveness/Views/WarningBox.swift @@ -53,7 +53,7 @@ struct WarningBox: View { .padding() .background( Rectangle() - .foregroundColor(.livenessWarningBackground) + .foregroundColor(Color(UIColor.hex("#FF8473"))) .cornerRadius(6) ) }