Skip to content

Commit

Permalink
feat(Auth): Adding forceAliasCreation option during confirmSignUp
Browse files Browse the repository at this point in the history
  • Loading branch information
harsh62 committed Nov 27, 2023
1 parent b9b5918 commit 13ca65b
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ public struct AWSAuthConfirmSignUpOptions {

public let metadata: [String: String]?

public init(metadata: [String: String]? = nil) {
public let forceAliasCreation: Bool?

public init(metadata: [String: String]? = nil,
forceAliasCreation: Bool? = nil) {
self.metadata = metadata
self.forceAliasCreation = forceAliasCreation
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ extension ConfirmSignUpInput {
confirmationCode: String,
clientMetadata: [String: String]?,
asfDeviceId: String?,
forceAliasCreation: Bool?,
environment: UserPoolEnvironment
) {

Expand All @@ -37,6 +38,7 @@ extension ConfirmSignUpInput {
clientId: configuration.clientId,
clientMetadata: clientMetadata,
confirmationCode: confirmationCode,
forceAliasCreation: forceAliasCreation,
secretHash: secretHash,
userContextData: userContextData,
username: username)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@ class AWSAuthConfirmSignUpTask: AuthConfirmSignUpTask, DefaultLogger {
for: request.username,
credentialStoreClient: authEnvironment.credentialsClient)
let metadata = (request.options.pluginOptions as? AWSAuthConfirmSignUpOptions)?.metadata
let forceAliasCreation = (request.options.pluginOptions as? AWSAuthConfirmSignUpOptions)?.forceAliasCreation
let client = try userPoolEnvironment.cognitoUserPoolFactory()
let input = ConfirmSignUpInput(username: request.username,
confirmationCode: request.code,
clientMetadata: metadata,
asfDeviceId: asfDeviceId,
forceAliasCreation: forceAliasCreation,
environment: userPoolEnvironment)
_ = try await client.confirmSignUp(input: input)
log.verbose("Received success")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class ConfirmSignUpInputTests: XCTestCase {
confirmationCode: "123",
clientMetadata: [:],
asfDeviceId: "asdfDeviceId",
forceAliasCreation: nil,
environment: environment)

XCTAssertNotNil(confirmSignUpInput.secretHash)
Expand All @@ -55,6 +56,7 @@ class ConfirmSignUpInputTests: XCTestCase {
confirmationCode: "123",
clientMetadata: [:],
asfDeviceId: nil,
forceAliasCreation: nil,
environment: environment)

XCTAssertNil(confirmSignUpInput.secretHash)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ class AWSAuthConfirmSignUpAPITests: BasePluginTest {
func testSuccessfulSignUp() async throws {

self.mockIdentityProvider = MockIdentityProvider(
mockConfirmSignUpResponse: { _ in
mockConfirmSignUpResponse: { request in
XCTAssertNil(request.clientMetadata)
XCTAssertNil(request.forceAliasCreation)
return .init()
}
)
Expand All @@ -47,11 +49,14 @@ class AWSAuthConfirmSignUpAPITests: BasePluginTest {
mockConfirmSignUpResponse: { request in
XCTAssertNotNil(request.clientMetadata)
XCTAssertEqual(request.clientMetadata?["key"], "value")
XCTAssertEqual(request.forceAliasCreation, true)
return .init()
}
)

let pluginOptions = AWSAuthConfirmSignUpOptions(metadata: ["key": "value"])
let pluginOptions = AWSAuthConfirmSignUpOptions(
metadata: ["key": "value"],
forceAliasCreation: true)
let options = AuthConfirmSignUpRequest.Options(pluginOptions: pluginOptions)
let result = try await self.plugin.confirmSignUp(
for: "jeffb",
Expand Down

0 comments on commit 13ca65b

Please sign in to comment.