Skip to content

Commit

Permalink
update namespacing
Browse files Browse the repository at this point in the history
  • Loading branch information
harsh62 committed Nov 28, 2023
1 parent 7a979c7 commit cf56827
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ enum PasswordlessCustomAuthRequestAction: String {

struct PasswordlessCustomAuthRequest {

private let namespace = "Amplify.Passwordless"

let signInMethod: PasswordlessCustomAuthSignInMethod
let action: PasswordlessCustomAuthRequestAction
let deliveryMedium: AuthPasswordlessDeliveryDestination?
Expand All @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit cf56827

Please sign in to comment.