From afef7e39a67d95c003cc33c59bdd0ce6963a71f3 Mon Sep 17 00:00:00 2001 From: Michiel Vrins Date: Thu, 23 Mar 2023 15:50:38 +0100 Subject: [PATCH 1/4] FP-34: Remove dart and pigeon apis for old error events + add invalidpin --- .../mobile/sdk/flutter/pigeonPlugin/Pigeon.kt | 12 ++----- example/lib/onegini_listener.dart | 11 +++---- ios/Classes/Pigeon.swift | 12 ++----- lib/onegini_event_listener.dart | 16 +++------ lib/pigeon.dart | 33 +++---------------- pigeons/onewelcome_pigeon_interface.dart | 6 +--- 6 files changed, 19 insertions(+), 71 deletions(-) diff --git a/android/src/main/kotlin/com/onegini/mobile/sdk/flutter/pigeonPlugin/Pigeon.kt b/android/src/main/kotlin/com/onegini/mobile/sdk/flutter/pigeonPlugin/Pigeon.kt index ac850844..cdb1c643 100644 --- a/android/src/main/kotlin/com/onegini/mobile/sdk/flutter/pigeonPlugin/Pigeon.kt +++ b/android/src/main/kotlin/com/onegini/mobile/sdk/flutter/pigeonPlugin/Pigeon.kt @@ -1320,16 +1320,8 @@ class NativeCallFlutterApi(private val binaryMessenger: BinaryMessenger) { callback() } } - /** Called when error event was received. */ - fun n2fEventError(errorArg: OWOneginiError, callback: () -> Unit) { - val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.NativeCallFlutterApi.n2fEventError", codec) - channel.send(listOf(errorArg)) { - callback() - } - } - /** Called whenever error occured. */ - fun n2fShowError(errorArg: OWOneginiError, callback: () -> Unit) { - val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.NativeCallFlutterApi.n2fShowError", codec) + fun n2fEventPinNotAllowed(errorArg: OWOneginiError, callback: () -> Unit) { + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.NativeCallFlutterApi.n2fEventPinNotAllowed", codec) channel.send(listOf(errorArg)) { callback() } diff --git a/example/lib/onegini_listener.dart b/example/lib/onegini_listener.dart index 08c9cdc3..e28f2d6d 100644 --- a/example/lib/onegini_listener.dart +++ b/example/lib/onegini_listener.dart @@ -47,12 +47,6 @@ class OneginiListener extends OneginiEventListener { showFlutterToast("${error.message} Code: ${error.code} "); } - @override - void showError(BuildContext buildContext, OneginiError error) { - showFlutterToast( - "${error.message} Code: ${error.code} " ?? "Something went wrong"); - } - @override void openPinScreenAuth(BuildContext buildContext) { Navigator.push( @@ -182,4 +176,9 @@ class OneginiListener extends OneginiEventListener { await Onegini.instance.userClient.handleRegisteredUserUrl(buildContext, url, signInType: WebSignInType.insideApp); } + + @override + void eventPinNotAllowed(OWOneginiError error) { + showFlutterToast("${error.message} Code: ${error.code}"); + } } diff --git a/ios/Classes/Pigeon.swift b/ios/Classes/Pigeon.swift index 72fa631e..4439a577 100644 --- a/ios/Classes/Pigeon.swift +++ b/ios/Classes/Pigeon.swift @@ -1223,16 +1223,8 @@ class NativeCallFlutterApi { completion() } } - /// Called when error event was received. - func n2fEventError(error errorArg: OWOneginiError, completion: @escaping () -> Void) { - let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.NativeCallFlutterApi.n2fEventError", binaryMessenger: binaryMessenger, codec: codec) - channel.sendMessage([errorArg] as [Any?]) { _ in - completion() - } - } - /// Called whenever error occured. - func n2fShowError(error errorArg: OWOneginiError, completion: @escaping () -> Void) { - let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.NativeCallFlutterApi.n2fShowError", binaryMessenger: binaryMessenger, codec: codec) + func n2fEventPinNotAllowed(error errorArg: OWOneginiError, completion: @escaping () -> Void) { + let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.NativeCallFlutterApi.n2fEventPinNotAllowed", binaryMessenger: binaryMessenger, codec: codec) channel.sendMessage([errorArg] as [Any?]) { _ in completion() } diff --git a/lib/onegini_event_listener.dart b/lib/onegini_event_listener.dart index b575752b..7f2e9f95 100644 --- a/lib/onegini_event_listener.dart +++ b/lib/onegini_event_listener.dart @@ -67,13 +67,11 @@ abstract class OneginiEventListener implements NativeCallFlutterApi { /// Called when error event was received. void eventError(BuildContext? buildContext, PlatformException error); - /// Called whenever error occured. - void showError( - BuildContext? buildContext, deprecatedError.OneginiError? error); - /// Called when custom event was received. void eventOther(BuildContext? buildContext, Event event); + void eventPinNotAllowed(OWOneginiError error); + @override void n2fCloseAuthOtp() { closeAuthOtp(_context); @@ -159,13 +157,7 @@ abstract class OneginiEventListener implements NativeCallFlutterApi { } @override - void n2fEventError(OWOneginiError error) { - eventError(_context, - PlatformException(code: error.code.toString(), message: error.message)); - } - - @override - void n2fShowError(OWOneginiError error) { - showError(_context, OneginiError(code: error.code, message: error.message)); + void n2fEventPinNotAllowed(OWOneginiError error) { + eventPinNotAllowed(error); } } diff --git a/lib/pigeon.dart b/lib/pigeon.dart index 40d69d1d..39299c50 100644 --- a/lib/pigeon.dart +++ b/lib/pigeon.dart @@ -1359,11 +1359,7 @@ abstract class NativeCallFlutterApi { /// Called when the FinishCustomRegistration event occurs and a response should be given void n2fEventFinishCustomRegistration(OWCustomInfo? customInfo, String providerId); - /// Called when error event was received. - void n2fEventError(OWOneginiError error); - - /// Called whenever error occured. - void n2fShowError(OWOneginiError error); + void n2fEventPinNotAllowed(OWOneginiError error); static void setup(NativeCallFlutterApi? api, {BinaryMessenger? binaryMessenger}) { { @@ -1605,38 +1601,19 @@ abstract class NativeCallFlutterApi { } { final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.NativeCallFlutterApi.n2fEventError', codec, - binaryMessenger: binaryMessenger); - if (api == null) { - channel.setMessageHandler(null); - } else { - channel.setMessageHandler((Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.NativeCallFlutterApi.n2fEventError was null.'); - final List args = (message as List?)!; - final OWOneginiError? arg_error = (args[0] as OWOneginiError?); - assert(arg_error != null, - 'Argument for dev.flutter.pigeon.NativeCallFlutterApi.n2fEventError was null, expected non-null OWOneginiError.'); - api.n2fEventError(arg_error!); - return; - }); - } - } - { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.NativeCallFlutterApi.n2fShowError', codec, + 'dev.flutter.pigeon.NativeCallFlutterApi.n2fEventPinNotAllowed', codec, binaryMessenger: binaryMessenger); if (api == null) { channel.setMessageHandler(null); } else { channel.setMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.NativeCallFlutterApi.n2fShowError was null.'); + 'Argument for dev.flutter.pigeon.NativeCallFlutterApi.n2fEventPinNotAllowed was null.'); final List args = (message as List?)!; final OWOneginiError? arg_error = (args[0] as OWOneginiError?); assert(arg_error != null, - 'Argument for dev.flutter.pigeon.NativeCallFlutterApi.n2fShowError was null, expected non-null OWOneginiError.'); - api.n2fShowError(arg_error!); + 'Argument for dev.flutter.pigeon.NativeCallFlutterApi.n2fEventPinNotAllowed was null, expected non-null OWOneginiError.'); + api.n2fEventPinNotAllowed(arg_error!); return; }); } diff --git a/pigeons/onewelcome_pigeon_interface.dart b/pigeons/onewelcome_pigeon_interface.dart index 83ba0740..4382de22 100644 --- a/pigeons/onewelcome_pigeon_interface.dart +++ b/pigeons/onewelcome_pigeon_interface.dart @@ -286,9 +286,5 @@ abstract class NativeCallFlutterApi { void n2fEventFinishCustomRegistration( OWCustomInfo? customInfo, String providerId); - /// Called when error event was received. - void n2fEventError(OWOneginiError error); - - /// Called whenever error occured. - void n2fShowError(OWOneginiError error); + void n2fEventPinNotAllowed(OWOneginiError error); } From 73b820004dc416e1c4bed65a91ae47669b05e9ae Mon Sep 17 00:00:00 2001 From: Michiel Vrins Date: Thu, 23 Mar 2023 15:52:46 +0100 Subject: [PATCH 2/4] FP-34: iOS: Use new invalidPinEvent --- ios/Classes/NativeBridge/Handlers/RegistrationHandler.swift | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ios/Classes/NativeBridge/Handlers/RegistrationHandler.swift b/ios/Classes/NativeBridge/Handlers/RegistrationHandler.swift index 3e258a2a..a7ae6208 100644 --- a/ios/Classes/NativeBridge/Handlers/RegistrationHandler.swift +++ b/ios/Classes/NativeBridge/Handlers/RegistrationHandler.swift @@ -106,8 +106,7 @@ class RegistrationHandler: NSObject, BrowserHandlerToRegisterHandlerProtocol { func handleDidReceivePinRegistrationChallenge(_ challenge: ONGCreatePinChallenge) { createPinChallenge = challenge if let pinError = mapErrorFromPinChallenge(challenge) { - // FIXME: I believe we are dealing here with an invalid pin that was supplied, we should send such an event. FP-34 - SwiftOneginiPlugin.flutterApi?.n2fShowError(error: OWOneginiError(code: Int64(pinError.code), message: pinError.errorDescription)) {} + SwiftOneginiPlugin.flutterApi?.n2fEventPinNotAllowed(error: OWOneginiError(code: Int64(pinError.code), message: pinError.errorDescription)) {} } else { // FIXME: we should be sending the pin length here. SwiftOneginiPlugin.flutterApi?.n2fOpenPinRequestScreen {} From 0063f06a7197675a7039972aa6d868eb402e40e5 Mon Sep 17 00:00:00 2001 From: Michiel Vrins Date: Thu, 23 Mar 2023 16:02:49 +0100 Subject: [PATCH 3/4] FP-34: Android: Remove old error Events and use pinNotAllowedEvent --- .../onegini/mobile/sdk/flutter/handlers/PinRequestHandler.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android/src/main/kotlin/com/onegini/mobile/sdk/flutter/handlers/PinRequestHandler.kt b/android/src/main/kotlin/com/onegini/mobile/sdk/flutter/handlers/PinRequestHandler.kt index b4fe113f..85193a1f 100644 --- a/android/src/main/kotlin/com/onegini/mobile/sdk/flutter/handlers/PinRequestHandler.kt +++ b/android/src/main/kotlin/com/onegini/mobile/sdk/flutter/handlers/PinRequestHandler.kt @@ -22,7 +22,7 @@ class PinRequestHandler @Inject constructor(private val nativeApi: NativeCallFlu } override fun onNextPinCreationAttempt(oneginiPinValidationError: OneginiPinValidationError) { - nativeApi.n2fEventError(OWOneginiError(oneginiPinValidationError.errorType.toLong(), oneginiPinValidationError.message ?: "")) {} + nativeApi.n2fEventPinNotAllowed(OWOneginiError(oneginiPinValidationError.errorType.toLong(), oneginiPinValidationError.message ?: "")) {} } override fun finishPinCreation() { From ba9f9a7ed3c6e641e3969136f89c022eb2368c27 Mon Sep 17 00:00:00 2001 From: Michiel Vrins Date: Thu, 23 Mar 2023 17:00:54 +0100 Subject: [PATCH 4/4] FP-34: Rename pinNotAllowed event --- example/lib/onegini_listener.dart | 2 +- lib/callbacks/onegini_pin_registration_callback.dart | 5 ++++- lib/onegini_event_listener.dart | 4 ++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/example/lib/onegini_listener.dart b/example/lib/onegini_listener.dart index e28f2d6d..7b45c1fa 100644 --- a/example/lib/onegini_listener.dart +++ b/example/lib/onegini_listener.dart @@ -178,7 +178,7 @@ class OneginiListener extends OneginiEventListener { } @override - void eventPinNotAllowed(OWOneginiError error) { + void pinNotAllowed(OWOneginiError error) { showFlutterToast("${error.message} Code: ${error.code}"); } } diff --git a/lib/callbacks/onegini_pin_registration_callback.dart b/lib/callbacks/onegini_pin_registration_callback.dart index 9c104f36..a675e170 100644 --- a/lib/callbacks/onegini_pin_registration_callback.dart +++ b/lib/callbacks/onegini_pin_registration_callback.dart @@ -6,13 +6,16 @@ import '../onegini.dart'; /// A callback for pin REGISTRATION. class OneginiPinRegistrationCallback { final api = UserClientApi(); + /// Cancels pin registration request. Future denyAuthenticationRequest() async { await api.pinDenyRegistrationRequest(); } /// Accepts pin registration and sent [pin] to the OneginiSdk. - Future acceptAuthenticationRequest(BuildContext? context, String pin) async { + @Deprecated("message") + Future acceptAuthenticationRequest( + BuildContext? context, String pin) async { Onegini.instance.setEventContext(context); await api.pinAcceptRegistrationRequest(pin); diff --git a/lib/onegini_event_listener.dart b/lib/onegini_event_listener.dart index 7f2e9f95..2fd79cc1 100644 --- a/lib/onegini_event_listener.dart +++ b/lib/onegini_event_listener.dart @@ -70,7 +70,7 @@ abstract class OneginiEventListener implements NativeCallFlutterApi { /// Called when custom event was received. void eventOther(BuildContext? buildContext, Event event); - void eventPinNotAllowed(OWOneginiError error); + void pinNotAllowed(OWOneginiError error); @override void n2fCloseAuthOtp() { @@ -158,6 +158,6 @@ abstract class OneginiEventListener implements NativeCallFlutterApi { @override void n2fEventPinNotAllowed(OWOneginiError error) { - eventPinNotAllowed(error); + pinNotAllowed(error); } }