Skip to content

Commit 03b72e9

Browse files
committed
feat(Auth): Updating the Sign In resolver to add new cases (#3104)
1 parent d8cea93 commit 03b72e9

File tree

8 files changed

+59
-8
lines changed

8 files changed

+59
-8
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,5 @@ GraphQLModelBasedTests-amplifyconfiguration.json
8686
GraphQLWithIAMIntegrationTests-amplifyconfiguration.json
8787
GraphQLWithIAMIntegrationTests-credentials.json
8888

89-
AWSDataStoreCategoryPluginIntegrationTests-amplifyconfiguration.json
89+
AWSDataStoreCategoryPluginIntegrationTests-amplifyconfiguration.json
90+
*.code-workspace

AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Service/ErrorMapping/RespondToAuthChallengeOutputError+AuthError.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ extension RespondToAuthChallengeOutputError: AuthErrorConvertible {
4949
AWSCognitoAuthError.invalidParameter)
5050
case .invalidSmsRoleAccessPolicyException(let exception):
5151
return AuthError.service(exception.message ?? "Invalid SMS Role Access Policy error",
52-
AuthPluginErrorConstants.invalidParameterError,
52+
AuthPluginErrorConstants.invalidSMSRoleError,
5353
AWSCognitoAuthError.smsRole)
5454
case .invalidSmsRoleTrustRelationshipException(let exception):
5555
return AuthError.service(exception.message ?? "Invalid SMS Role Trust Relationship error",
56-
AuthPluginErrorConstants.invalidParameterError,
56+
AuthPluginErrorConstants.invalidSMSRoleError,
5757
AWSCognitoAuthError.smsRole)
5858
case .invalidUserPoolConfigurationException(let exception):
5959
return AuthError.configuration(exception.message ?? "Invalid UserPool Configuration error",

AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Service/ErrorMapping/VerifySoftwareTokenOutputError+AuthError.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ extension VerifySoftwareTokenOutputError: AuthErrorConvertible {
1919
case .enableSoftwareTokenMFAException(let exception):
2020
return AuthError.service(
2121
exception.message ?? "Unable to enable software token MFA",
22-
AuthPluginErrorConstants.serviceError,
22+
AuthPluginErrorConstants.softwareTokenNotFoundError,
2323
AWSCognitoAuthError.softwareTokenMFANotEnabled)
2424
case .forbiddenException(let forbiddenException):
2525
return .service(

AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/StateMachine/Resolvers/SignIn/SignInState+Resolver.swift

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,14 @@ extension SignInState {
142142
actions: [action])
143143
}
144144

145+
if let signInEvent = event as? SignInEvent,
146+
case .initiateTOTPSetup(_, let challengeResponse) = signInEvent.eventType {
147+
let action = InitializeTOTPSetup(
148+
authResponse: challengeResponse)
149+
return .init(newState: .resolvingTOTPSetup(.notStarted, signInEventData),
150+
actions: [action])
151+
}
152+
145153
let resolution = CustomSignInState.Resolver().resolve(
146154
oldState: customSignInState, byApplying: event)
147155
let signingInWithCustom = SignInState.signingInWithCustom(
@@ -178,6 +186,14 @@ extension SignInState {
178186
actions: [action])
179187
}
180188

189+
if let signInEvent = event as? SignInEvent,
190+
case .initiateTOTPSetup(_, let challengeResponse) = signInEvent.eventType {
191+
let action = InitializeTOTPSetup(
192+
authResponse: challengeResponse)
193+
return .init(newState: .resolvingTOTPSetup(.notStarted, signInEventData),
194+
actions: [action])
195+
}
196+
181197
let resolution = MigrateSignInState.Resolver().resolve(
182198
oldState: migrateSignInState, byApplying: event)
183199
let signingInWithMigration = SignInState.signingInViaMigrateAuth(
@@ -215,6 +231,19 @@ extension SignInState {
215231
signInMethod), actions: [action])
216232
}
217233

234+
if let signInEvent = event as? SignInEvent,
235+
case .initiateTOTPSetup(let username, let challengeResponse) = signInEvent.eventType {
236+
let action = InitializeTOTPSetup(
237+
authResponse: challengeResponse)
238+
return .init(
239+
newState: .resolvingTOTPSetup(
240+
.notStarted,
241+
.init(username: username,
242+
password: nil,
243+
signInMethod: signInMethod)),
244+
actions: [action])
245+
}
246+
218247
let resolution = SignInChallengeState.Resolver().resolve(
219248
oldState: challengeState,
220249
byApplying: event)
@@ -246,6 +275,14 @@ extension SignInState {
246275
actions: [action])
247276
}
248277

278+
if let signInEvent = event as? SignInEvent,
279+
case .initiateTOTPSetup(_, let challengeResponse) = signInEvent.eventType {
280+
let action = InitializeTOTPSetup(
281+
authResponse: challengeResponse)
282+
return .init(newState: .resolvingTOTPSetup(.notStarted, signInEventData),
283+
actions: [action])
284+
}
285+
249286
if let signInEvent = event as? SignInEvent,
250287
case .confirmDevice(let signedInData) = signInEvent.eventType {
251288
let action = ConfirmDevice(signedInData: signedInData)
@@ -318,6 +355,19 @@ extension SignInState {
318355
signInMethod), actions: [action])
319356
}
320357

358+
if let signInEvent = event as? SignInEvent,
359+
case .initiateTOTPSetup(let username, let challengeResponse) = signInEvent.eventType {
360+
let action = InitializeTOTPSetup(
361+
authResponse: challengeResponse)
362+
return .init(newState:
363+
.resolvingTOTPSetup(
364+
.notStarted,
365+
.init(username: username,
366+
password: nil,
367+
signInMethod: signInMethod)),
368+
actions: [action])
369+
}
370+
321371
let resolution = DeviceSRPState.Resolver().resolve(oldState: deviceSrpState,
322372
byApplying: event)
323373
let resolvingDeviceSrpa = SignInState.resolvingDeviceSrpa(resolution.newState)

AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/FetchMFAPreferenceTask.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import AWSPluginsCore
1111
import ClientRuntime
1212
import AWSCognitoIdentityProvider
1313

14-
protocol AuthFetchMFAPreferenceTask: AmplifyAuthTask where Request == Void,
14+
protocol AuthFetchMFAPreferenceTask: AmplifyAuthTask where Request == Never,
1515
Success == UserMFAPreference,
1616
Failure == AuthError {}
1717

AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/Protocols/AuthDeleteUserTask.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import Foundation
88
import Amplify
99

10-
protocol AuthDeleteUserTask: AmplifyAuthTask where Request == Void, Success == Void, Failure == AuthError { }
10+
protocol AuthDeleteUserTask: AmplifyAuthTask where Request == Never, Success == Void, Failure == AuthError { }
1111

1212
public extension HubPayload.EventName.Auth {
1313

AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/Protocols/AuthSetUpTOTPTask.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import Foundation
99
import Amplify
1010

11-
protocol AuthSetUpTOTPTask: AmplifyAuthTask where Request == Void, Success == TOTPSetupDetails, Failure == AuthError {}
11+
protocol AuthSetUpTOTPTask: AmplifyAuthTask where Request == Never, Success == TOTPSetupDetails, Failure == AuthError {}
1212

1313
public extension HubPayload.EventName.Auth {
1414

AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/UpdateMFAPreferenceTask.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import AWSPluginsCore
1111
import ClientRuntime
1212
import AWSCognitoIdentityProvider
1313

14-
protocol AuthUpdateMFAPreferenceTask: AmplifyAuthTask where Request == Void,
14+
protocol AuthUpdateMFAPreferenceTask: AmplifyAuthTask where Request == Never,
1515
Success == Void,
1616
Failure == AuthError {}
1717

0 commit comments

Comments
 (0)