-
Notifications
You must be signed in to change notification settings - Fork 202
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Auth): Adding TOTP states, events, data models and resolvers
- Loading branch information
Showing
13 changed files
with
440 additions
and
3 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
30 changes: 30 additions & 0 deletions
30
...ins/Auth/Sources/AWSCognitoAuthPlugin/StateMachine/CodeGen/Data/SignInTOTPSetupData.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,30 @@ | ||
// | ||
// Copyright Amazon.com Inc. or its affiliates. | ||
// All Rights Reserved. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
import Amplify | ||
|
||
struct SignInTOTPSetupData { | ||
|
||
let secretCode: String | ||
let session: String | ||
let username: String | ||
|
||
} | ||
|
||
extension SignInTOTPSetupData: CustomDebugDictionaryConvertible { | ||
var debugDictionary: [String: Any] { | ||
[ | ||
"sharedSecret": secretCode.redacted(), | ||
"session": session.masked(), | ||
"username": username.masked() | ||
] | ||
} | ||
} | ||
|
||
extension SignInTOTPSetupData: Codable { } | ||
|
||
extension SignInTOTPSetupData: Equatable { } |
71 changes: 71 additions & 0 deletions
71
...lugins/Auth/Sources/AWSCognitoAuthPlugin/StateMachine/CodeGen/Events/SetUpTOTPEvent.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,71 @@ | ||
// | ||
// Copyright Amazon.com Inc. or its affiliates. | ||
// All Rights Reserved. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
import Foundation | ||
|
||
/// Session value created by the service | ||
typealias UserSession = String | ||
|
||
struct SetUpTOTPEvent: StateMachineEvent { | ||
|
||
enum EventType { | ||
|
||
case setUpTOTP(SignInResponseBehavior) | ||
|
||
case waitForAnswer(SignInTOTPSetupData) | ||
|
||
case verifyChallengeAnswer(ConfirmSignInEventData) | ||
|
||
case respondToAuthChallenge(UserSession) | ||
|
||
case verified | ||
|
||
case throwError(SignInError) | ||
|
||
} | ||
|
||
let id: String | ||
let eventType: EventType | ||
let time: Date? | ||
|
||
var type: String { | ||
switch eventType { | ||
case .setUpTOTP: return "SetUpTOTPEvent.setUpTOTP" | ||
case .verified: return "SetUpTOTPEvent.verified" | ||
case .verifyChallengeAnswer: return "SetUpTOTPEvent.verifyChallengeAnswer" | ||
case .waitForAnswer: return "SetUpTOTPEvent.waitForAnswer" | ||
case .respondToAuthChallenge: return "SetUpTOTPEvent.respondToAuthChallenge" | ||
case .throwError: return "SetUpTOTPEvent.throwError" | ||
} | ||
} | ||
|
||
init(id: String = UUID().uuidString, | ||
eventType: EventType, | ||
time: Date? = nil) { | ||
self.id = id | ||
self.eventType = eventType | ||
self.time = time | ||
} | ||
} | ||
|
||
extension SetUpTOTPEvent.EventType: Equatable { | ||
static func == (lhs: SetUpTOTPEvent.EventType, rhs: SetUpTOTPEvent.EventType) -> Bool { | ||
switch (lhs, rhs) { | ||
case (.setUpTOTP, .setUpTOTP), | ||
(.verified, .verified), | ||
(.verifyChallengeAnswer, .verifyChallengeAnswer), | ||
(.waitForAnswer, .waitForAnswer), | ||
(.respondToAuthChallenge, .respondToAuthChallenge), | ||
(.throwError, .throwError): | ||
return true | ||
default: | ||
return false | ||
} | ||
} | ||
|
||
|
||
} |
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
28 changes: 28 additions & 0 deletions
28
...SCognitoAuthPlugin/StateMachine/CodeGen/States/DebugInfo/SignInTOTPSetupState+Debug.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,28 @@ | ||
// | ||
// Copyright Amazon.com Inc. or its affiliates. | ||
// All Rights Reserved. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
import Foundation | ||
|
||
extension SignInTOTPSetupState { | ||
|
||
var debugDictionary: [String: Any] { | ||
var additionalMetadataDictionary: [String: Any] = [:] | ||
switch self { | ||
case .waitingForAnswer(let signInTOTPSetupData): | ||
additionalMetadataDictionary = signInTOTPSetupData.debugDictionary | ||
case .verifying(let signInSetupData, let confirmSignInEventData): | ||
additionalMetadataDictionary = confirmSignInEventData.debugDictionary | ||
additionalMetadataDictionary = additionalMetadataDictionary.merging( | ||
signInSetupData.debugDictionary, | ||
uniquingKeysWith: {$1}) | ||
case .error(let error): | ||
additionalMetadataDictionary["error"] = error | ||
default: additionalMetadataDictionary = [:] | ||
} | ||
return [type: additionalMetadataDictionary] | ||
} | ||
} |
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
57 changes: 57 additions & 0 deletions
57
.../Auth/Sources/AWSCognitoAuthPlugin/StateMachine/CodeGen/States/SignInTOTPSetupState.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,57 @@ | ||
// | ||
// Copyright Amazon.com Inc. or its affiliates. | ||
// All Rights Reserved. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
import Foundation | ||
|
||
enum SignInTOTPSetupState: State { | ||
|
||
case notStarted | ||
|
||
case setUpTOTP | ||
|
||
case waitingForAnswer(SignInTOTPSetupData) | ||
|
||
case verifying(SignInTOTPSetupData, ConfirmSignInEventData) | ||
|
||
case respondingToAuthChallenge | ||
|
||
case success | ||
|
||
case error(SignInTOTPSetupData?, SignInError) | ||
} | ||
|
||
extension SignInTOTPSetupState { | ||
|
||
var type: String { | ||
switch self { | ||
case .notStarted: return "SignInTOTPSetupState.notStarted" | ||
case .setUpTOTP: return "SignInTOTPSetupState.setUpTOTP" | ||
case .waitingForAnswer: return "SignInTOTPSetupState.waitingForAnswer" | ||
case .verifying: return "SignInTOTPSetupState.verifying" | ||
case .respondingToAuthChallenge: return "SignInTOTPSetupState.respondingToAuthChallenge" | ||
case .success: return "SignInTOTPSetupState.success" | ||
case .error: return "SignInTOTPSetupState.error" | ||
} | ||
} | ||
} | ||
|
||
extension SignInTOTPSetupState: Equatable { | ||
static func == (lhs: SignInTOTPSetupState, rhs: SignInTOTPSetupState) -> Bool { | ||
switch (lhs, rhs) { | ||
case (.notStarted, .notStarted), | ||
(.setUpTOTP, .setUpTOTP), | ||
(.waitingForAnswer, .waitingForAnswer), | ||
(.verifying, .verifying), | ||
(.respondingToAuthChallenge, .respondingToAuthChallenge), | ||
(.success, .success), | ||
(.error, .error): | ||
return true | ||
default: return false | ||
} | ||
} | ||
|
||
} |
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
Oops, something went wrong.