-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Refactored based on TOTP API review (#45)
* feat: Converting to a dedicated MFA Selection state * feat: converting to a dedicated setup totp state and refactoring options * chore: increasing the tolerance to 1 percent for snapshot testing * worked on review commetns * trying out deducing step information when creating a view * worked on API review changes * added unit tests * worked on review comments.. * worked on review comments.
- Loading branch information
Showing
17 changed files
with
540 additions
and
155 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
Sources/Authenticator/States/ContinueSignInWithMFASelectionState.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// | ||
// Copyright Amazon.com Inc. or its affiliates. | ||
// All Rights Reserved. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
import Amplify | ||
import AWSCognitoAuthPlugin | ||
import SwiftUI | ||
|
||
/// The state observed by the Continue Sign In With MFA Selection content views, representing the ``Authenticator`` is in ``AuthenticatorStep/continueSignInWithMFASelection`` step. | ||
public class ContinueSignInWithMFASelectionState: AuthenticatorBaseState { | ||
|
||
/// The confirmation code provided by the user | ||
@Published public var selectedMFAType: MFAType? | ||
|
||
init(authenticatorState: AuthenticatorStateProtocol, | ||
allowedMFATypes: AllowedMFATypes) { | ||
self.allowedMFATypes = allowedMFATypes | ||
super.init(authenticatorState: authenticatorState, | ||
credentials: Credentials()) | ||
} | ||
|
||
/// The `Amplify.AllowedMFATypes` associated with this state. | ||
public let allowedMFATypes: AllowedMFATypes | ||
|
||
/// Attempts to continue the user's sign in using the provided confirmation code. | ||
/// | ||
/// Automatically sets the Authenticator's next step accordingly, as well as the | ||
/// ``AuthenticatorBaseState/isBusy`` and ``AuthenticatorBaseState/message`` properties. | ||
/// - Throws: An `Amplify.AuthenticationError` if the operation fails | ||
public func continueSignIn() async throws { | ||
guard let selectedMFAType = selectedMFAType else { | ||
log.error("MFA type not selected") | ||
return | ||
} | ||
|
||
setBusy(true) | ||
do { | ||
log.verbose("Attempting to confirm Sign In with Code") | ||
let result = try await authenticationService.confirmSignIn( | ||
challengeResponse: selectedMFAType.challengeResponse, | ||
options: nil | ||
) | ||
let nextStep = try await nextStep(for: result) | ||
|
||
setBusy(false) | ||
|
||
authenticatorState.setCurrentStep(nextStep) | ||
} catch { | ||
log.error("Confirm Sign In with Code failed") | ||
let authenticationError = self.error(for: error) | ||
setMessage(authenticationError) | ||
throw authenticationError | ||
} | ||
} | ||
} |
Oops, something went wrong.