diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Models/PasswordlessCustomAuthRequest.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Models/PasswordlessCustomAuthRequest.swift index 4f65844835..8c7218157b 100644 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Models/PasswordlessCustomAuthRequest.swift +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Models/PasswordlessCustomAuthRequest.swift @@ -20,6 +20,8 @@ enum PasswordlessCustomAuthRequestAction: String { struct PasswordlessCustomAuthRequest { + private let namespace = "Amplify.Passwordless" + let signInMethod: PasswordlessCustomAuthSignInMethod let action: PasswordlessCustomAuthRequestAction let deliveryMedium: AuthPasswordlessDeliveryDestination? @@ -34,11 +36,11 @@ struct PasswordlessCustomAuthRequest { func toDictionary() -> [String: String] { var dictionary = [ - "signInMethod": signInMethod.rawValue, - "action": action.rawValue + namespace + ".signInMethod": signInMethod.rawValue, + namespace + ".action": action.rawValue ] if let deliveryMedium = deliveryMedium { - dictionary["deliveryMedium"] = deliveryMedium.rawValue + dictionary[namespace + ".deliveryMedium"] = deliveryMedium.rawValue } return dictionary } diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/AWSAuthConfirmSignInWithOTPTask.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/AWSAuthConfirmSignInWithOTPTask.swift index c4eff718ec..ee4e820abf 100644 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/AWSAuthConfirmSignInWithOTPTask.swift +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/AWSAuthConfirmSignInWithOTPTask.swift @@ -97,15 +97,12 @@ class AWSAuthConfirmSignInWithOTPTask: AuthConfirmSignInWithOTPTask, DefaultLogg } private func createConfirmSignInEventData() -> ConfirmSignInEventData { - // TODO: - // Discuss if we should have dedicated options for ConfirmSignWith OTP - // Because `AWSAuthConfirmSignInOptions` has `friendlyDeviceName` and `userAttributes` - // that is not supported by this task. Customers might get confused that these are supported fields. var passwordlessMetadata = confirmSignInRequestMetadata.toDictionary() if let customerMetadata = (request.options.pluginOptions as? AWSAuthConfirmSignInOptions)?.metadata { passwordlessMetadata.merge(customerMetadata, uniquingKeysWith: { passwordlessMetadata, customerMetadata in - // TODO: Discuss with team to namespace passwordless metadata - // Giving precedence to passwordless metadata. + // Ideally key collision won't happen, because passwordless has been namespaced + // if for some reason collision still happens, + // prioritizing passwordlessFlow keys for flow to continue without any issues. passwordlessMetadata }) diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/AWSAuthSignInWithOTPTask.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/AWSAuthSignInWithOTPTask.swift index 8c719b2942..7f61d4a690 100644 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/AWSAuthSignInWithOTPTask.swift +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/AWSAuthSignInWithOTPTask.swift @@ -173,8 +173,9 @@ class AWSAuthSignInWithOTPTask: AuthSignInWithOTPTask, DefaultLogger { private func sendEventForProvidingAuthParameters() async { var passwordlessFlowMetadata = signInMetadataRequestMetadata.toDictionary() passwordlessFlowMetadata.merge(customerClientMetadata()) { passwordlessFlowMetadata, customerClientMetadata in - // TODO: Discuss with team to namespace passwordless metadata - // Giving precedence to passwordless metadata. + // Ideally key collision won't happen, because passwordless has been namespaced + // if for some reason collision still happens, + // prioritizing passwordlessFlow keys for flow to continue without any issues. passwordlessFlowMetadata } let confirmSignInEventData = ConfirmSignInEventData( diff --git a/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/TaskTests/ClientBehaviorTests/SignIn/AWSAuthConfirmSignInWithOTPTaskTests.swift b/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/TaskTests/ClientBehaviorTests/SignIn/AWSAuthConfirmSignInWithOTPTaskTests.swift index 1d5ccf8815..5f2022a511 100644 --- a/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/TaskTests/ClientBehaviorTests/SignIn/AWSAuthConfirmSignInWithOTPTaskTests.swift +++ b/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/TaskTests/ClientBehaviorTests/SignIn/AWSAuthConfirmSignInWithOTPTaskTests.swift @@ -53,8 +53,8 @@ class AWSAuthConfirmSignInWithOTPTaskTests: BasePluginTest { mockRespondToAuthChallengeResponse: { request in XCTAssertEqual(request.challengeName, .customChallenge) XCTAssertEqual(request.challengeResponses?["ANSWER"], "code") - XCTAssertEqual(request.clientMetadata?["signInMethod"], "OTP") - XCTAssertEqual(request.clientMetadata?["action"], "CONFIRM") + XCTAssertEqual(request.clientMetadata?["Amplify.Passwordless.signInMethod"], "OTP") + XCTAssertEqual(request.clientMetadata?["Amplify.Passwordless.action"], "CONFIRM") XCTAssertEqual(request.clientMetadata?["somekey"], "somevalue") return .testData() }) diff --git a/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/TaskTests/ClientBehaviorTests/SignIn/AWSAuthSignInWithOTPTaskTests.swift b/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/TaskTests/ClientBehaviorTests/SignIn/AWSAuthSignInWithOTPTaskTests.swift index d3967c2c5d..ad4f0c06cb 100644 --- a/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/TaskTests/ClientBehaviorTests/SignIn/AWSAuthSignInWithOTPTaskTests.swift +++ b/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/TaskTests/ClientBehaviorTests/SignIn/AWSAuthSignInWithOTPTaskTests.swift @@ -42,9 +42,9 @@ class AWSAuthSignInWithOTPTaskTests: BasePluginTest { ], session: "someSession") }, mockRespondToAuthChallengeResponse: { input in - XCTAssertEqual(input.clientMetadata?["signInMethod"], "OTP") - XCTAssertEqual(input.clientMetadata?["action"], "REQUEST") - XCTAssertEqual(input.clientMetadata?["deliveryMedium"], "EMAIL") + XCTAssertEqual(input.clientMetadata?["Amplify.Passwordless.signInMethod"], "OTP") + XCTAssertEqual(input.clientMetadata?["Amplify.Passwordless.action"], "REQUEST") + XCTAssertEqual(input.clientMetadata?["Amplify.Passwordless.deliveryMedium"], "EMAIL") XCTAssertEqual(input.clientMetadata?["somekey"], "somevalue") return RespondToAuthChallengeOutput(