-
Notifications
You must be signed in to change notification settings - Fork 236
Expand file tree
/
Copy pathAuthPluginErrorConstants.swift
More file actions
424 lines (320 loc) · 18.3 KB
/
Copy pathAuthPluginErrorConstants.swift
File metadata and controls
424 lines (320 loc) · 18.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
//
// Copyright Amazon.com Inc. or its affiliates.
// All Rights Reserved.
//
// SPDX-License-Identifier: Apache-2.0
//
import Foundation
import Amplify
typealias AuthPluginErrorString = (errorDescription: ErrorDescription, recoverySuggestion: RecoverySuggestion)
typealias AuthPluginValidationErrorString = (field: Field,
errorDescription: ErrorDescription,
recoverySuggestion: RecoverySuggestion)
enum AuthPluginErrorConstants {
static let protectedDataUnavailableError: AuthPluginErrorString = (
"Protected data is not yet available",
"Delay Amplify calls until `UIApplication.shared.isProtectedDataAvailable` returns true"
)
static let decodeConfigurationError: AuthPluginErrorString = (
"Unable to decode configuration",
"Make sure the plugin configuration is JSONValue")
static let configurationObjectExpected: AuthPluginErrorString = (
"Configuration was not a dictionary literal",
"Make sure the value for the plugin is a dictionary literal")
static let hostedUISecurityFailedError: AuthPluginErrorString = (
"Found invalid parameter while parsing the webUI redirect URL",
"Make sure that the signIn URL has not been modified during the signIn flow")
static let hostedUIUserCancelledError: AuthPluginErrorString = (
"User cancelled the signIn flow and could not be completed.",
"Present the signIn UI again for the user to sign in")
static let hostedUIUserCancelledSignOutError: AuthPluginErrorString = (
"User cancelled the signOut flow and could not be completed.",
"Present the signOut UI again for the user to sign out")
static let hostedUIInvalidPresentation: AuthPluginErrorString = (
"Presentation context provided is invalid or not present",
"Retry by providing a presentation context to present the webUI")
static let hostedUIUnableToStartASWebAuthenticationSession: AuthPluginErrorString = (
"Unable to start a ASWebAuthenticationSession",
"Make sure that the app can present an ASWebAuthenticationSession")
static let hostedUISignInURI: AuthPluginErrorString = (
"SignIn URI could not be created",
"Check the configuration to make sure that HostedUI related information are present")
static let hostedUITokenURI: AuthPluginErrorString = (
"Token URI could not be created",
"Check the configuration to make sure that HostedUI related information are present")
static let hostedUISignOutURI: AuthPluginErrorString = (
"SignOut URI could not be created",
"Check the configuration to make sure that HostedUI related information are present")
static let hostedUISignOutRedirectURI: AuthPluginErrorString = (
"Callback URL could not be retrieved",
"Check the configuration to make sure that HostedUI related information are present")
static let hostedUIProofCalculation: AuthPluginErrorString = (
"Proof calculation failed",
"Reach out with amplify team via github to raise an issue")
static let tokenParsingError: AuthPluginErrorString = (
"Token returned by service could not be parsed",
"Check if the the configuration provided are correct")
static let userInvalidError: AuthPluginErrorString = (
"Could not validate the user",
"Get the current user Auth.getCurrentUser() and make the request")
static let identityIdSignOutError: AuthPluginErrorString = (
"There is no user signed in to retreive identity id",
"Call Auth.signIn to sign in a user or enable unauthenticated access in AWS Cognito Identity Pool")
static let awsCredentialsSignOutError: AuthPluginErrorString = (
"There is no user signed in to retreive AWS credentials",
"Call Auth.signIn to sign in a user or enable unauthenticated access in AWS Cognito Identity Pool")
static let cognitoTokensSignOutError: AuthPluginErrorString = (
"There is no user signed in to retreive cognito tokens",
"Call Auth.signIn to sign in a user and then call Auth.fetchSession")
static let userSubSignOutError: AuthPluginErrorString = (
"There is no user signed in to retreive user sub",
"Call Auth.signIn to sign in a user and then call Auth.fetchSession")
static let identityIdOfflineError: AuthPluginErrorString = (
"A network error occured while trying to fetch identity id",
"Try again with exponential backoff")
static let awsCredentialsOfflineError: AuthPluginErrorString = (
"A network error occured while trying to fetch AWS credentials",
"Try again with exponential backoff")
static let usersubOfflineError: AuthPluginErrorString = (
"A network error occured while trying to fetch user sub",
"Try again with exponential backoff")
static let cognitoTokenOfflineError: AuthPluginErrorString = (
"A network error occured while trying to fetch AWS Cognito Tokens",
"Try again with exponential backoff")
static let identityIdServiceError: AuthPluginErrorString = (
"A serivce error occured while trying to fetch identity id",
"Try again with exponential backoff")
static let awsCredentialsServiceError: AuthPluginErrorString = (
"A service error occured while trying to fetch AWS credentials",
"Try again with exponential backoff")
static let identityIdSessionExpiredError: AuthPluginErrorString = (
"Session expired could not fetch identity id",
"Invoke Auth.signIn to re-authenticate the user")
static let awsCredentialsSessionExpiredError: AuthPluginErrorString = (
"Session expired could not fetch AWS Credentials",
"Invoke Auth.signIn to re-authenticate the user")
static let usersubSessionExpiredError: AuthPluginErrorString = (
"Session expired could not fetch user sub",
"Invoke Auth.signIn to re-authenticate the user")
static let cognitoTokensSessionExpiredError: AuthPluginErrorString = (
"Session expired could not fetch cognito tokens",
"Invoke Auth.signIn to re-authenticate the user")
static let cognitoTokenSignedInThroughCIDPError: AuthPluginErrorString = (
"User is not signed in through Cognito User pool",
"Tokens are not valid with user signed in through AWS Cognito Identity Pool")
static let userSubSignedInThroughCIDPError: AuthPluginErrorString = (
"User is not signed in through Cognito User pool",
"User sub are not valid with user signed in through AWS Cognito Identity Pool")
static let signedInIdentityIdWithNoCIDPError: AuthPluginErrorString = (
"Could not fetch identity Id, AWS Cognito Identity Pool is not configured",
"Follow the steps to configure AWS Cognito Identity Pool and try again")
static let signedInAWSCredentialsWithNoCIDPError: AuthPluginErrorString = (
"Could not fetch AWS Credentials, AWS Cognito Identity Pool is not configured",
"Follow the steps to configure AWS Cognito Identity Pool and try again")
static let fetchAttributeSignedOutError: AuthPluginErrorString = (
"Could not fetch attributes, there is no user signed in to the Auth category",
"SignIn to Auth category by using one of the sign in methods and then call user attributes apis")
static let updateAttributeSignedOutError: AuthPluginErrorString = (
"Could not update attributes, there is no user signed in to the Auth category",
"SignIn to Auth category by using one of the sign in methods and then call user attributes apis")
static let resendAttributeCodeSignedOutError: AuthPluginErrorString = (
"Could not resend attribute confirmation code, there is no user signed in to the Auth category",
"SignIn to Auth category by using one of the sign in methods and then call user attributes apis")
static let confirmAttributeSignedOutError: AuthPluginErrorString = (
"Could not confirm attribute, there is no user signed in to the Auth category",
"SignIn to Auth category by using one of the sign in methods and then call user attributes apis")
static let changePasswordSignedOutError: AuthPluginErrorString = (
"Could not change password, there is no user signed in to the Auth category",
"Change password require a user signed in to Auth category, use one of the signIn apis to signIn")
static let changePasswordUnableToSignInError: AuthPluginErrorString = (
"Could not change password, the user session is expired",
"Re-authenticate the user by using one of the signIn apis")
static let userSignedOutError: AuthPluginErrorString = (
"There is no user signed in to the Auth category",
"SignIn to Auth category by using one of the sign in methods and then try again")
static let associateWebAuthnCredentialUserCancelledError: AuthPluginErrorString = (
"User cancelled the creation of a new WebAuthn credential",
"Invoke the associate WebAuthn credential flow again"
)
static let associateWebAuthnCredentialAlreadyExistError: AuthPluginErrorString = (
"The user already has associated a WebAuthn credential with this device",
"Remove the old WebAuthn credential and try again"
)
static let associateWebAuthnCreationFailedError: AuthPluginErrorString = (
"Unable to complete the association of the given WebAuthn credential",
"Invoke the associate WebAuthn credential flow again"
)
static let signInWithWebAuthnUserCancelledError: AuthPluginErrorString = (
"User cancelled the signIn flow and could not be completed",
"Invoke the sign in with WebAuthn flow again"
)
static let signInWithWebAuthnAssertionFailedError: AuthPluginErrorString = (
"Unable to complete assertion of the given WebAuthn credential",
"Invoke the sign in with WebAuthn flow again"
)
}
// Field validation errors
extension AuthPluginErrorConstants {
static let signInUsernameError: AuthPluginValidationErrorString = (
"username",
"Username is required to signIn",
"Make sure that a valid username is passed during signIn"
)
static let signInPasswordError: AuthPluginValidationErrorString = (
"password",
"Password is required to signIn",
"Make sure that a valid password is passed during signIn"
)
static let signUpUsernameError: AuthPluginValidationErrorString = (
"username",
"Username is required to signUp",
"Make sure that a valid username is passed for signUp"
)
static let signUpPasswordError: AuthPluginValidationErrorString = (
"password",
"Password is required to signUp",
"Make sure that a valid password is passed for signUp"
)
static let confirmSignUpUsernameError: AuthPluginValidationErrorString = (
"username",
"Username is required to confirmSignUp",
"Make sure that a valid username is passed for confirmSignUp"
)
static let resendSignUpCodeUsernameError: AuthPluginValidationErrorString = (
"username",
"Username is required to confirmSignUp",
"Make sure that a valid username is passed for confirmSignUp"
)
static let confirmSignUpCodeError: AuthPluginValidationErrorString = (
"code",
"code is required to confirmSignUp",
"Make sure that a valid code is passed for confirmSignUp"
)
static let confirmSignInChallengeResponseError: AuthPluginValidationErrorString = (
"challengeResponse",
"challengeResponse is required to confirmSignIn",
"Make sure that a valid challenge response is passed for confirmSignIn"
)
static let confirmSignInMFASelectionResponseError: AuthPluginValidationErrorString = (
"challengeResponse",
"challengeResponse for MFA selection can only have SMS_MFA or SOFTWARE_TOKEN_MFA.",
"""
Make sure that a valid challenge response is passed for confirmSignIn.
Try using `MFAType.totp.challengeResponse` or `MFAType.sms.challengeResponse` as the challenge response
"""
)
static let confirmSignInFactorSelectionResponseError: AuthPluginValidationErrorString = (
"challengeResponse",
"challengeResponse for factor selection can only be one of the `AuthFactorType` values.",
"""
Make sure that a valid challenge response is passed for confirmSignIn.
Try using `AuthFactorType.<type>.challengeResponse` as the challenge response.
"""
)
static let confirmResetPasswordUsernameError: AuthPluginValidationErrorString = (
"username",
"username is required to confirmResetPassword",
"Make sure that a valid username is passed for confirmResetPassword"
)
static let confirmResetPasswordNewPasswordError: AuthPluginValidationErrorString = (
"newPassword",
"newPassword is required to confirmResetPassword",
"Make sure that a valid newPassword is passed for confirmResetPassword"
)
static let confirmResetPasswordCodeError: AuthPluginValidationErrorString = (
"confirmationCode",
"confirmationCode is required to confirmResetPassword",
"Make sure that a valid confirmationCode is passed for confirmResetPassword"
)
static let resetPasswordUsernameError: AuthPluginValidationErrorString = (
"username",
"username is required to resetPassword",
"Make sure that a valid username is passed for resetPassword"
)
}
// Recovery Messages
extension AuthPluginErrorConstants {
static let userNotFoundError: RecoverySuggestion = "Make sure that the user is present in the backend"
static let aliasExistsError: RecoverySuggestion = "Try with a different alias for the user"
static let codeDeliveryError: RecoverySuggestion = "Make sure that the delivery destination is valid"
static let codeMismatchError: RecoverySuggestion = "Retry with a valid code"
static let codeExpiredError: RecoverySuggestion = "Rerun the flow to send the code again"
static let lambdaError: RecoverySuggestion = "Make sure that the lambda configuration is correct"
static let invalidParameterError: RecoverySuggestion = "Make sure that the parameters passed are valid"
static let invalidPasswordError: RecoverySuggestion = "Make sure that the password is valid"
static let mfaMethodNotFoundError: RecoverySuggestion = "Make sure that the user pool has a valid MFA configured"
static let passwordResetRequired: RecoverySuggestion = "Reset the user password using the changePassword API"
static let resourceNotFoundError: RecoverySuggestion = "Make sure that the user pool has a requested resource"
static let softwareTokenNotFoundError: RecoverySuggestion = "Enable the software token MFA for the user"
static let tooManyFailedError: RecoverySuggestion = "User might have tried too many times with failed input"
static let tooManyRequestError: RecoverySuggestion = """
Make sure the requests send are controlled and the errors are properly handled
"""
static let limitExceededError: RecoverySuggestion = """
Make sure that the request made to the particular AWS resources are under the resource quota limits
"""
static let configurationError: RecoverySuggestion = """
Make sure that the amplify configuration passed to Auth plugin is valid
"""
static let userNotConfirmedError: RecoverySuggestion = "Confirm the user by calling confirmSignUp api"
static let userNameExistsError: RecoverySuggestion = "Invoke the api with a different username"
static let errorLoadingPageError: RecoverySuggestion = "Make sure that the UI is configured correctly"
static let deviceNotRememberedError: RecoverySuggestion = "Call remeberDevice to track the device"
static let invalidStateError: RecoverySuggestion = """
Operation performed is not a valid operation for the current auth state
"""
static let notAuthorizedError: RecoverySuggestion = """
Check whether the given values are correct and the user is authorized to perform the operation
"""
static let hostedUIBadRequestError: RecoverySuggestion = "Retry the webUi signIn"
static let configurationMissingError: RecoverySuggestion = """
Could not read Cognito Service configuration from the auth configuration. Make sure that auth category
is properly configured and auth information are present in the configuration. You can use Amplify CLI to
configure the auth category
"""
static let externalServiceException: RecoverySuggestion = """
An exception thrown when a dependent service such as Facebook or Twitter is not responding
"""
static let limitExceededException: RecoverySuggestion = """
The total number of user pools has exceeded a preset limit
"""
static let resourceConflictException: RecoverySuggestion = """
Check if the login is already linked to another account
"""
static let invalidEmailRoleError: RecoverySuggestion = """
Check the email identity used with Cognito Service
"""
static let invalidSMSRoleError: RecoverySuggestion = """
Check the role provided for SMS configuration in Cognito Service
"""
static let serviceError: RecoverySuggestion = """
Received an error message from the service
"""
static let forbiddenError: RecoverySuggestion = """
Check if you are allowed to make this request based on the web ACL thats associated with your user pool
"""
static let concurrentModificationException: RecoverySuggestion = """
Make sure the requests sent are controlled and concurrent operations are handled properly
"""
static let webAuthnChallengeNotFound: RecoverySuggestion = """
Call this API after receiving an WebAuthn challenge
"""
static let webAuthnClientMismatch: RecoverySuggestion = """
Use an App client that supports passkey authentication
"""
static let webAuthnCredentialNotSupported: RecoverySuggestion = """
Create credentials using a supported device
"""
static let webAuthnNotEnabled: RecoverySuggestion = """
Check that WebAuthn authentication is enabled
"""
static let webAuthnOriginNotAllowed: RecoverySuggestion = """
Check that the device origin is registered as an allowed origin
"""
static let webAuthnRelyingPartyMismatch: RecoverySuggestion = """
Check that the relying party ID is correct
"""
static let webAuthnConfigurationMissing: RecoverySuggestion = """
Check that the device is registered
"""
}