Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/fp 34 #68

Merged
merged 4 commits into from
Mar 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Any?>(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<Any?>(binaryMessenger, "dev.flutter.pigeon.NativeCallFlutterApi.n2fShowError", codec)
fun n2fEventPinNotAllowed(errorArg: OWOneginiError, callback: () -> Unit) {
val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.NativeCallFlutterApi.n2fEventPinNotAllowed", codec)
channel.send(listOf(errorArg)) {
callback()
}
Expand Down
11 changes: 5 additions & 6 deletions example/lib/onegini_listener.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -182,4 +176,9 @@ class OneginiListener extends OneginiEventListener {
await Onegini.instance.userClient.handleRegisteredUserUrl(buildContext, url,
signInType: WebSignInType.insideApp);
}

@override
void pinNotAllowed(OWOneginiError error) {
showFlutterToast("${error.message} Code: ${error.code}");
}
}
3 changes: 1 addition & 2 deletions ios/Classes/NativeBridge/Handlers/RegistrationHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
Expand Down
12 changes: 2 additions & 10 deletions ios/Classes/Pigeon.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
5 changes: 4 additions & 1 deletion lib/callbacks/onegini_pin_registration_callback.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@ import '../onegini.dart';
/// A callback for pin REGISTRATION.
class OneginiPinRegistrationCallback {
final api = UserClientApi();

/// Cancels pin registration request.
Future<void> denyAuthenticationRequest() async {
await api.pinDenyRegistrationRequest();
}

/// Accepts pin registration and sent [pin] to the OneginiSdk.
Future<void> acceptAuthenticationRequest(BuildContext? context, String pin) async {
@Deprecated("message")
Future<void> acceptAuthenticationRequest(
BuildContext? context, String pin) async {
Onegini.instance.setEventContext(context);

await api.pinAcceptRegistrationRequest(pin);
Expand Down
16 changes: 4 additions & 12 deletions lib/onegini_event_listener.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 pinNotAllowed(OWOneginiError error);

@override
void n2fCloseAuthOtp() {
closeAuthOtp(_context);
Expand Down Expand Up @@ -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) {
pinNotAllowed(error);
}
}
33 changes: 5 additions & 28 deletions lib/pigeon.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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}) {
{
Expand Down Expand Up @@ -1605,38 +1601,19 @@ abstract class NativeCallFlutterApi {
}
{
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
'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<Object?> args = (message as List<Object?>?)!;
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<Object?> channel = BasicMessageChannel<Object?>(
'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<Object?> args = (message as List<Object?>?)!;
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;
});
}
Expand Down
6 changes: 1 addition & 5 deletions pigeons/onewelcome_pigeon_interface.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}