From 21025f9554ee3456eb104b06f92c7dd820707ee0 Mon Sep 17 00:00:00 2001 From: Michiel Vrins Date: Tue, 2 May 2023 13:01:49 +0200 Subject: [PATCH 1/6] Add enums for all error_codes --- lib/errors/error_codes.dart | 137 ++++++++++++++++++++++++++++++++++++ 1 file changed, 137 insertions(+) create mode 100644 lib/errors/error_codes.dart diff --git a/lib/errors/error_codes.dart b/lib/errors/error_codes.dart new file mode 100644 index 00000000..d7ae9149 --- /dev/null +++ b/lib/errors/error_codes.dart @@ -0,0 +1,137 @@ +// Dev note: When editing these error codes, make sure to update them in the native wrapper code aswel. + +/// Errors from the flutter sdk, some of these errors can only occur on a single platform. +enum WrapperErrorCodes { + genericError(code: 8000), + notAuthenticatedUser(code: 8040), + notAuthenticatedImplicit(code: 8041), + notFoundUserProfile(code: 8042), + notFoundAuthenticator(code: 8043), + notFoundIdentityProvider(code: 8044), + + /// Android only + notFoundSecurityController(code: 8045), + + httpRequestErrorInternal(code: 8046), + httpRequestErrorCode(code: 8047), + + /// iOS only + httpRequestErrorNoResponse(code: 8048), + + /// Android only + onewelcomeSdkNotInitialized(code: 8049), + + invalidUrl(code: 8050), + notInProgressCustomRegistration(code: 8051), + notInProgressAuthentication(code: 8052), + notInProgressOtpAuthentication(code: 8053), + notInProgressPinCreation(code: 8054), + notInProgressFingerprintAuthentication(code: 8055), + + /// iOS only. Android will throw actionAlreadyInProgress + alreadyInProgressMobileAuth(code: 8056), + + actionNotAllowedCustomRegistrationCancel(code: 8057), + actionNotAllowedBrowserRegistrationCancel(code: 8058), + + /// Android only + configError(code: 8059), + + biometricAuthenticationNotAvailable(code: 8060); + + final int code; + + const WrapperErrorCodes({required this.code}); +} + +/// Error from the native sdk's, some of these errors can only occur on a single platform. +enum PlatformErrorCodes { + networkConnectivityProblem(code: 9000), + serverNotReachable(code: 9001), + deviceDeregistered(code: 9002), + userDeregistered(code: 9003), + outdatedApp(code: 9004), + outdatedOs(code: 9005), + actionCanceled(code: 9006), + actionAlreadyInProgress(code: 9007), + deviceRegistrationError(code: 9008), + + /// iOS only + authenticationErrorInvalidPin(code: 9009), + + userNotAuthenticated(code: 9010), + pinBlacklisted(code: 9011), + pinIsASequence(code: 9012), + pinUsesSimilarDigits(code: 9013), + wrongPinLength(code: 9014), + invalidAuthenticator(code: 9015), + deviceAlreadyEnrolled(code: 9016), + enrollmentNotAvailable(code: 9017), + userAlreadyEnrolled(code: 9018), + userDisenrolled(code: 9020), + mobileAuthenticationNotEnrolled(code: 9021), + authenticatorDeregistered(code: 9022), + + /// Android only + mobileAuthenticationDisenrolled(code: 9023), + + dataStorageNotAvailable(code: 9024), + + /// iOS only + genericErrorUnrecoverableDataState(code: 9025), + + /// iOS only + userNotAuthenticatedImplicitly(code: 9026), + + customAuthenticatorFailure(code: 9027), + + /// iOS only + alreadyHandled(code: 9029), + + authenticationErrorBiometricAuthenticatorFailure(code: 9030), + + /// Android only + invalidDatetime(code: 9031), + + generalError(code: 10000), + configurationError(code: 10001), + invalidState(code: 10002), + localDeregistration(code: 10003), + authenticatorAlreadyRegistered(code: 10004), + + /// Android only + fidoAuthenticationDisabledDeprecated(code: 10005), + + authenticatorNotSupported(code: 10006), + authenticatorNotRegistered(code: 10007), + authenticatorPinDeregistrationNotPossible(code: 10008), + localLogout(code: 10009), + + /// iOS only + fetchInvalidMethod(code: 10010), + + deviceNotAuthenticated(code: 10012), + mobileAuthenticationRequestNotFound(code: 10013), + invalidRequest(code: 10015), + + /// Android only + fidoServerNotReachableDeprecated(code: 10016), + + customAuthenticationDisabled(code: 10017), + notHandleable(code: 10018), + + /// iOS only + fetchInvalidHeaders(code: 10019), + + /// Android only + invalidIdentityProvider(code: 10020), + + customRegistrationExpired(code: 10021), + customRegistrationFailure(code: 10022), + singleSignOnDisabled(code: 10023), + appIntegrityFailure(code: 10024); + + final int code; + + const PlatformErrorCodes({required this.code}); +} From 2756366f1d31b23185e48ae536427a97fd188221 Mon Sep 17 00:00:00 2001 From: Michiel Vrins Date: Tue, 2 May 2023 13:13:43 +0200 Subject: [PATCH 2/6] Use Error enums where hardcoded values were used --- example/lib/screens/user_screen.dart | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/example/lib/screens/user_screen.dart b/example/lib/screens/user_screen.dart index 7750e2dd..239019a0 100644 --- a/example/lib/screens/user_screen.dart +++ b/example/lib/screens/user_screen.dart @@ -2,6 +2,7 @@ import 'dart:async'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; +import 'package:onegini/errors/error_codes.dart'; import 'package:onegini/events/onewelcome_events.dart'; import 'package:onegini/model/request_details.dart'; import 'package:onegini/onegini.dart'; @@ -83,7 +84,8 @@ class _UserScreenState extends State with RouteAware { _biometricAuthenticator = biometricAuthenticator; }); } on PlatformException catch (err) { - if (err.code != "8060") { + if (err.code != + WrapperErrorCodes.biometricAuthenticationNotAvailable.code) { showFlutterToast(err.message); } } @@ -136,12 +138,11 @@ class _UserScreenState extends State with RouteAware { Onegini.instance.userClient.changePin().catchError((error) { if (error is PlatformException) { showFlutterToast(error.message); - // FIXME: this should be extracted into a seperate method and should also use constants (dont exist yet) - if (error.code == "8002" || - error.code == "9002" || - error.code == "9003" || - error.code == "9010" || - error.code == "10012") { + // FIXME: this should be extracted into a seperate method + if (error.code == WrapperErrorCodes.notAuthenticatedUser || + error.code == PlatformErrorCodes.deviceDeregistered || + error.code == PlatformErrorCodes.userDeregistered || + error.code == PlatformErrorCodes.userNotAuthenticated) { Navigator.pushReplacement( context, MaterialPageRoute(builder: (_) => LoginScreen()), From e3eb71279e7f353e7ec1695a800c07e355523c52 Mon Sep 17 00:00:00 2001 From: Michiel Vrins Date: Tue, 2 May 2023 13:14:12 +0200 Subject: [PATCH 3/6] Add comments to make sure both places get adjusted --- .../com/onegini/mobile/sdk/flutter/OneWelcomeWrapperErrors.kt | 1 + ios/Classes/NativeBridge/Errors/ErrorMapper.swift | 1 + 2 files changed, 2 insertions(+) diff --git a/android/src/main/kotlin/com/onegini/mobile/sdk/flutter/OneWelcomeWrapperErrors.kt b/android/src/main/kotlin/com/onegini/mobile/sdk/flutter/OneWelcomeWrapperErrors.kt index 14c7432d..6bcfcaac 100644 --- a/android/src/main/kotlin/com/onegini/mobile/sdk/flutter/OneWelcomeWrapperErrors.kt +++ b/android/src/main/kotlin/com/onegini/mobile/sdk/flutter/OneWelcomeWrapperErrors.kt @@ -1,5 +1,6 @@ package com.onegini.mobile.sdk.flutter +// When editing these errors, make sure to also update the errors in lib/errors/error_codes.dart enum class OneWelcomeWrapperErrors(val code: Int, val message: String) { GENERIC_ERROR(8000, "Something went wrong"), NOT_AUTHENTICATED_USER(8040, "There is currently no User Profile authenticated"), diff --git a/ios/Classes/NativeBridge/Errors/ErrorMapper.swift b/ios/Classes/NativeBridge/Errors/ErrorMapper.swift index b347b63f..1806be38 100644 --- a/ios/Classes/NativeBridge/Errors/ErrorMapper.swift +++ b/ios/Classes/NativeBridge/Errors/ErrorMapper.swift @@ -1,6 +1,7 @@ // swiftlint:disable cyclomatic_complexity import OneginiSDKiOS +// When editing these errors, make sure to also update the errors in lib/errors/error_codes.dart enum OneWelcomeWrapperError { case genericError case notAuthenticatedUser From 1982f3dc0d20e5eef1e9fe1f94fb1ff1356528e8 Mon Sep 17 00:00:00 2001 From: Michiel Vrins Date: Tue, 2 May 2023 14:40:57 +0200 Subject: [PATCH 4/6] Update max-sdk to 4.0.0 --- pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pubspec.yaml b/pubspec.yaml index 9357c204..69409ca8 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -4,7 +4,7 @@ version: 2.0.1 homepage: https://www.onegini.com environment: - sdk: ">=2.12.0 <3.0.0" + sdk: ">=2.12.0 <4.0.0" flutter: ">=1.12.0" dependencies: From fdf4692ce0926a05bb04493feea07788a6a2494f Mon Sep 17 00:00:00 2001 From: Michiel Vrins Date: Wed, 3 May 2023 10:04:32 +0200 Subject: [PATCH 5/6] Remove generated files from swiftlint --- example/ios/.swiftlint.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/example/ios/.swiftlint.yml b/example/ios/.swiftlint.yml index e36d81bd..39c7f2d1 100644 --- a/example/ios/.swiftlint.yml +++ b/example/ios/.swiftlint.yml @@ -14,7 +14,7 @@ excluded: # paths to ignore during linting. Takes precedence over `included`. - .swiftlint.yml - OneginiTests - OneginiUITests - - .symlinks/plugins/onegini/ios/Classes/Pigeon.swift + - .symlinks/plugins/onegini/ios/Classes/Pigeon.gen.swift # If true, SwiftLint will not fail if no lintable files are found. allow_zero_lintable_files: false From 2a19e2d3c2a3ff317e14960eb5c87435ab8d1f21 Mon Sep 17 00:00:00 2001 From: Michiel Vrins Date: Wed, 3 May 2023 10:06:22 +0200 Subject: [PATCH 6/6] Change the error_codes to static const String instead of enum --- example/lib/screens/user_screen.dart | 3 +- lib/errors/error_codes.dart | 166 +++++++++++++-------------- 2 files changed, 81 insertions(+), 88 deletions(-) diff --git a/example/lib/screens/user_screen.dart b/example/lib/screens/user_screen.dart index 239019a0..5ec3aa12 100644 --- a/example/lib/screens/user_screen.dart +++ b/example/lib/screens/user_screen.dart @@ -84,8 +84,7 @@ class _UserScreenState extends State with RouteAware { _biometricAuthenticator = biometricAuthenticator; }); } on PlatformException catch (err) { - if (err.code != - WrapperErrorCodes.biometricAuthenticationNotAvailable.code) { + if (err.code != WrapperErrorCodes.biometricAuthenticationNotAvailable) { showFlutterToast(err.message); } } diff --git a/lib/errors/error_codes.dart b/lib/errors/error_codes.dart index d7ae9149..1459d4bf 100644 --- a/lib/errors/error_codes.dart +++ b/lib/errors/error_codes.dart @@ -1,137 +1,131 @@ // Dev note: When editing these error codes, make sure to update them in the native wrapper code aswel. /// Errors from the flutter sdk, some of these errors can only occur on a single platform. -enum WrapperErrorCodes { - genericError(code: 8000), - notAuthenticatedUser(code: 8040), - notAuthenticatedImplicit(code: 8041), - notFoundUserProfile(code: 8042), - notFoundAuthenticator(code: 8043), - notFoundIdentityProvider(code: 8044), +class WrapperErrorCodes { + static const String genericError = "8000"; + static const String notAuthenticatedUser = "8040"; + static const String notAuthenticatedImplicit = "8041"; + static const String notFoundUserProfile = "8042"; + static const String notFoundAuthenticator = "8043"; + static const String notFoundIdentityProvider = "8044"; /// Android only - notFoundSecurityController(code: 8045), + static const String notFoundSecurityController = "8045"; - httpRequestErrorInternal(code: 8046), - httpRequestErrorCode(code: 8047), + static const String httpRequestErrorInternal = "8046"; + static const String httpRequestErrorCode = "8047"; /// iOS only - httpRequestErrorNoResponse(code: 8048), + static const String httpRequestErrorNoResponse = "8048"; /// Android only - onewelcomeSdkNotInitialized(code: 8049), + static const String onewelcomeSdkNotInitialized = "8049"; - invalidUrl(code: 8050), - notInProgressCustomRegistration(code: 8051), - notInProgressAuthentication(code: 8052), - notInProgressOtpAuthentication(code: 8053), - notInProgressPinCreation(code: 8054), - notInProgressFingerprintAuthentication(code: 8055), + static const String invalidUrl = "8050"; + static const String notInProgressCustomRegistration = "8051"; + static const String notInProgressAuthentication = "8052"; + static const String notInProgressOtpAuthentication = "8053"; + static const String notInProgressPinCreation = "8054"; + static const String notInProgressFingerprintAuthentication = "8055"; /// iOS only. Android will throw actionAlreadyInProgress - alreadyInProgressMobileAuth(code: 8056), + static const String alreadyInProgressMobileAuth = "8056"; - actionNotAllowedCustomRegistrationCancel(code: 8057), - actionNotAllowedBrowserRegistrationCancel(code: 8058), + static const String actionNotAllowedCustomRegistrationCancel = "8057"; + static const String actionNotAllowedBrowserRegistrationCancel = "8058"; /// Android only - configError(code: 8059), + static const String configError = "8059"; - biometricAuthenticationNotAvailable(code: 8060); - - final int code; - - const WrapperErrorCodes({required this.code}); + static const String biometricAuthenticationNotAvailable = "8060"; } +const String networkConnectivityProblem = "9000"; + /// Error from the native sdk's, some of these errors can only occur on a single platform. -enum PlatformErrorCodes { - networkConnectivityProblem(code: 9000), - serverNotReachable(code: 9001), - deviceDeregistered(code: 9002), - userDeregistered(code: 9003), - outdatedApp(code: 9004), - outdatedOs(code: 9005), - actionCanceled(code: 9006), - actionAlreadyInProgress(code: 9007), - deviceRegistrationError(code: 9008), +class PlatformErrorCodes { + static const String networkConnectivityProblem = "9000"; + static const String serverNotReachable = "9001"; + static const String deviceDeregistered = "9002"; + static const String userDeregistered = "9003"; + static const String outdatedApp = "9004"; + static const String outdatedOs = "9005"; + static const String actionCanceled = "9006"; + static const String actionAlreadyInProgress = "9007"; + static const String deviceRegistrationError = "9008"; /// iOS only - authenticationErrorInvalidPin(code: 9009), - - userNotAuthenticated(code: 9010), - pinBlacklisted(code: 9011), - pinIsASequence(code: 9012), - pinUsesSimilarDigits(code: 9013), - wrongPinLength(code: 9014), - invalidAuthenticator(code: 9015), - deviceAlreadyEnrolled(code: 9016), - enrollmentNotAvailable(code: 9017), - userAlreadyEnrolled(code: 9018), - userDisenrolled(code: 9020), - mobileAuthenticationNotEnrolled(code: 9021), - authenticatorDeregistered(code: 9022), + static const String authenticationErrorInvalidPin = "9009"; + + static const String userNotAuthenticated = "9010"; + static const String pinBlacklisted = "9011"; + static const String pinIsASequence = "9012"; + static const String pinUsesSimilarDigits = "9013"; + static const String wrongPinLength = "9014"; + static const String invalidAuthenticator = "9015"; + static const String deviceAlreadyEnrolled = "9016"; + static const String enrollmentNotAvailable = "9017"; + static const String userAlreadyEnrolled = "9018"; + static const String userDisenrolled = "9020"; + static const String mobileAuthenticationNotEnrolled = "9021"; + static const String authenticatorDeregistered = "9022"; /// Android only - mobileAuthenticationDisenrolled(code: 9023), + static const String mobileAuthenticationDisenrolled = "9023"; - dataStorageNotAvailable(code: 9024), + static const String dataStorageNotAvailable = "9024"; /// iOS only - genericErrorUnrecoverableDataState(code: 9025), + static const String genericErrorUnrecoverableDataState = "9025"; /// iOS only - userNotAuthenticatedImplicitly(code: 9026), + static const String userNotAuthenticatedImplicitly = "9026"; - customAuthenticatorFailure(code: 9027), + static const String customAuthenticatorFailure = "9027"; /// iOS only - alreadyHandled(code: 9029), + static const String alreadyHandled = "9029"; - authenticationErrorBiometricAuthenticatorFailure(code: 9030), + static const String authenticationErrorBiometricAuthenticatorFailure = "9030"; /// Android only - invalidDatetime(code: 9031), + static const String invalidDatetime = "9031"; - generalError(code: 10000), - configurationError(code: 10001), - invalidState(code: 10002), - localDeregistration(code: 10003), - authenticatorAlreadyRegistered(code: 10004), + static const String generalError = "10000"; + static const String configurationError = "10001"; + static const String invalidState = "10002"; + static const String localDeregistration = "10003"; + static const String authenticatorAlreadyRegistered = "10004"; /// Android only - fidoAuthenticationDisabledDeprecated(code: 10005), + static const String fidoAuthenticationDisabledDeprecated = "10005"; - authenticatorNotSupported(code: 10006), - authenticatorNotRegistered(code: 10007), - authenticatorPinDeregistrationNotPossible(code: 10008), - localLogout(code: 10009), + static const String authenticatorNotSupported = "10006"; + static const String authenticatorNotRegistered = "10007"; + static const String authenticatorPinDeregistrationNotPossible = "10008"; + static const String localLogout = "10009"; /// iOS only - fetchInvalidMethod(code: 10010), + static const String fetchInvalidMethod = "10010"; - deviceNotAuthenticated(code: 10012), - mobileAuthenticationRequestNotFound(code: 10013), - invalidRequest(code: 10015), + static const String deviceNotAuthenticated = "10012"; + static const String mobileAuthenticationRequestNotFound = "10013"; + static const String invalidRequest = "10015"; /// Android only - fidoServerNotReachableDeprecated(code: 10016), + static const String fidoServerNotReachableDeprecated = "10016"; - customAuthenticationDisabled(code: 10017), - notHandleable(code: 10018), + static const String customAuthenticationDisabled = "10017"; + static const String notHandleable = "10018"; /// iOS only - fetchInvalidHeaders(code: 10019), + static const String fetchInvalidHeaders = "10019"; /// Android only - invalidIdentityProvider(code: 10020), - - customRegistrationExpired(code: 10021), - customRegistrationFailure(code: 10022), - singleSignOnDisabled(code: 10023), - appIntegrityFailure(code: 10024); - - final int code; + static const String invalidIdentityProvider = "10020"; - const PlatformErrorCodes({required this.code}); + static const String customRegistrationExpired = "10021"; + static const String customRegistrationFailure = "10022"; + static const String singleSignOnDisabled = "10023"; + static const String appIntegrityFailure = "10024"; }