This repository has been archived by the owner on Oct 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added improved error handling and Open API generated code (#90)
* feat(PSG-3976): added openapi generated code * Refactor auth methods to use OpenAPI generated code (#86) * refactor(PSG-3976): otp & ml auth methods refactor * refactor(PSG-3976): refactored passkey methods * refactor(PSG-3976): remove olde MagicLink struct * refactor(PSG-3976): removed unused api client code * Finish replacing old Passage API code with generated code. (#87) * refactor(PSG-3976): otp & ml auth methods refactor * refactor(PSG-3976): refactored passkey methods * refactor(PSG-3976): remove olde MagicLink struct * refactor(PSG-3976): removed unused api client code * refactor: removed `PassageAPIClient` * refactor: cleaned up unused models * Updated integration tests (#88) * refactor(PSG-3976): otp & ml auth methods refactor * refactor(PSG-3976): refactored passkey methods * refactor(PSG-3976): remove olde MagicLink struct * refactor(PSG-3976): removed unused api client code * refactor: removed `PassageAPIClient` * refactor: cleaned up unused models * refactor: removed PassageSettings class * refactor: update app info tests * refactor: updated get user tests * refactor: updated otp tests * refactor: updated magic link tests * refactor: updated change contact tests * refactor: updated current user tests * refactor: update device tests * refactor: updated session tests * refactor: updated social auth tests * refactor: removed outdated unit tests * refactor: removed unnecessary static test data * refactor: misc test cleanup * Update Sources/Passage/PassageAuth.swift Signed-off-by: Ricky Padilla <[email protected]> --------- Signed-off-by: Ricky Padilla <[email protected]> * Added improved error enums (#89) * chore: removed old unit tests * feat: added script for fixing generated code * fix: fixed passkey login issue w user id * chore: added `CONTRIBUTING.md` and updated code gen fix script. * chore: misc cleanup * chore: misc cleanup * fix: add try safety to identifierExists method * chore: add error explanation to `identifierExists` * feat: added more auth error cases * fix: fixed auth new error cases * chore: increased mailosaur email check retry count --------- Signed-off-by: Ricky Padilla <[email protected]>
- Loading branch information
1 parent
aae2ac1
commit 857245d
Showing
295 changed files
with
13,394 additions
and
2,817 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 was deleted.
Oops, something went wrong.
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,11 @@ | ||
## Code generation | ||
|
||
1. Run below command to update the OpenAPI generated code: | ||
``` | ||
openapi-generator generate -i https://api.swaggerhub.com/apis/passage/passage-auth-api/1 -g swift5 --additional-properties=responseAs=AsyncAwait -o Sources/Passage/generated | ||
``` | ||
|
||
2. Run script to fix known generated code issues: | ||
``` | ||
python3 Sources/Passage/fix_generated_code.py | ||
``` |
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
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,40 @@ | ||
import AuthenticationServices | ||
|
||
public enum AddDeviceError: PassageError { | ||
|
||
case authorizationFailed | ||
case canceled | ||
case credentialChallengeParsingFailed | ||
case inactiveUser | ||
case invalidRequest | ||
case unauthorized | ||
case unspecified | ||
|
||
public static func convert(error: Error) -> AddDeviceError { | ||
// Check if error is already proper | ||
if let addDeviceError = error as? AddDeviceError { | ||
return addDeviceError | ||
} | ||
// Handle client error | ||
if let errorResponse = error as? ErrorResponse { | ||
guard let (statusCode, errorData) = PassageErrorData.getData(from: errorResponse) else { | ||
return .unspecified | ||
} | ||
switch errorData.code { | ||
case Model400Code.request.rawValue: return .invalidRequest | ||
case Model403Code.userNotActive.rawValue: return .inactiveUser | ||
default: () | ||
} | ||
if statusCode == 401 { | ||
return .unauthorized | ||
} | ||
return .unspecified | ||
} | ||
// Handle authorization error | ||
if let authError = error as? ASAuthorizationError { | ||
return authError.code == .canceled ? .canceled : .authorizationFailed | ||
} | ||
return .unspecified | ||
} | ||
|
||
} |
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,26 @@ | ||
import Foundation | ||
|
||
public enum AppInfoError: PassageError { | ||
|
||
case appNotFound | ||
case unspecified | ||
|
||
public static func convert(error: Error) -> AppInfoError { | ||
// Check if error is already proper | ||
if let appInfoError = error as? AppInfoError { | ||
return appInfoError | ||
} | ||
// Handle client error | ||
if let errorResponse = error as? ErrorResponse { | ||
guard let (_, errorData) = PassageErrorData.getData(from: errorResponse) else { | ||
return .unspecified | ||
} | ||
if errorData.code == Model404Code.appNotFound.rawValue { | ||
return .appNotFound | ||
} | ||
return .unspecified | ||
} | ||
return .unspecified | ||
} | ||
|
||
} |
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,15 @@ | ||
import Foundation | ||
|
||
public enum PassageConfigurationError: Error { | ||
case cannotFindPassagePlist | ||
case cannotFindAppId | ||
|
||
public var description: String { | ||
switch self { | ||
case .cannotFindAppId: | ||
return "Cannot find required Passage.plist file." | ||
case .cannotFindPassagePlist: | ||
return "Cannot find your Passage app id in your Passage.plist file" | ||
} | ||
} | ||
} |
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,29 @@ | ||
import Foundation | ||
|
||
public enum GetMagicLinkStatusError: PassageError { | ||
|
||
case invalidRequest | ||
case magicLinkNotFound | ||
case unspecified | ||
|
||
public static func convert(error: Error) -> GetMagicLinkStatusError { | ||
// Check if error is already proper | ||
if let error = error as? GetMagicLinkStatusError { | ||
return error | ||
} | ||
// Handle client error | ||
if let errorResponse = error as? ErrorResponse { | ||
guard let (_, errorData) = PassageErrorData.getData(from: errorResponse) else { | ||
return .unspecified | ||
} | ||
switch errorData.code { | ||
case Model400Code.request.rawValue: return .invalidRequest | ||
case Model404Code.magicLinkNotFound.rawValue: return .magicLinkNotFound | ||
default: () | ||
} | ||
return .unspecified | ||
} | ||
return .unspecified | ||
} | ||
|
||
} |
Oops, something went wrong.