From 71954b922e25156b269be3b8e99c13f62f4e03e4 Mon Sep 17 00:00:00 2001 From: Raymond <88292511+RaymondFrogParking@users.noreply.github.com> Date: Wed, 26 Jan 2022 10:36:30 +1300 Subject: [PATCH 1/2] Update signIn return value Android: if user cancels the login, it throws an PlatformException with details - the same behavior as iOS. Return true if no error occurs --- .../flutter_okta_sdk/okta/entities/Errors.kt | 1 + .../okta/operations/RegisterCallback.kt | 27 ++++++++++--------- lib/flutter_okta_sdk.dart | 6 ++++- pubspec.yaml | 2 +- 4 files changed, 22 insertions(+), 14 deletions(-) diff --git a/android/src/main/kotlin/com/sonikro/flutter_okta_sdk/okta/entities/Errors.kt b/android/src/main/kotlin/com/sonikro/flutter_okta_sdk/okta/entities/Errors.kt index c3ad34f..506aef6 100644 --- a/android/src/main/kotlin/com/sonikro/flutter_okta_sdk/okta/entities/Errors.kt +++ b/android/src/main/kotlin/com/sonikro/flutter_okta_sdk/okta/entities/Errors.kt @@ -13,4 +13,5 @@ enum class Errors(val errorCode: String, val errorMessage: String) { GENERIC_ERROR("-1100", "Generic Error"), METHOD_NOT_IMPLEMENTED("-1200", "This method is not implemented"), NO_CONTEXT("-1300", "No current context exists"), + CANCELLED_ERROR("-1400", "Operation cancelled"), } \ No newline at end of file diff --git a/android/src/main/kotlin/com/sonikro/flutter_okta_sdk/okta/operations/RegisterCallback.kt b/android/src/main/kotlin/com/sonikro/flutter_okta_sdk/okta/operations/RegisterCallback.kt index cf68867..e6882b6 100644 --- a/android/src/main/kotlin/com/sonikro/flutter_okta_sdk/okta/operations/RegisterCallback.kt +++ b/android/src/main/kotlin/com/sonikro/flutter_okta_sdk/okta/operations/RegisterCallback.kt @@ -31,32 +31,35 @@ fun registerCallback(activity: Activity) { result[Constants.RESOLVE_TYPE_KEY] = Constants.AUTHORIZED result[Constants.ACCESS_TOKEN_KEY] = tokens.accessToken - PendingOperation.success(result) + PendingOperation.success(true) + } catch (e: AuthorizationException) { - result[Constants.ERROR_CODE_KEY] = Errors.SIGN_IN_FAILED.errorCode - result[Constants.ERROR_MSG_KEY] = Errors.SIGN_IN_FAILED.errorMessage + //result[Constants.ERROR_CODE_KEY] = Errors.SIGN_IN_FAILED.errorCode + //result[Constants.ERROR_MSG_KEY] = Errors.SIGN_IN_FAILED.errorMessage - PendingOperation.success(result) + PendingOperation.error(Errors.SIGN_IN_FAILED,Errors.SIGN_IN_FAILED.errorMessage ) } } else if (status == AuthorizationStatus.SIGNED_OUT) { sessionClient.clear() - result[Constants.RESOLVE_TYPE_KEY] = Constants.SIGNED_OUT - PendingOperation.success(result) + //result[Constants.RESOLVE_TYPE_KEY] = Constants.SIGNED_OUT + PendingOperation.success(true) + } else { + PendingOperation.error(Errors.SIGN_IN_FAILED, Errors.SIGN_IN_FAILED.errorMessage) } } override fun onError(msg: String?, exception: AuthorizationException?) { val result = mutableMapOf() - result[Constants.ERROR_CODE_KEY] = Errors.OKTA_OIDC_ERROR.errorMessage - result[Constants.ERROR_MSG_KEY] = msg + //result[Constants.ERROR_CODE_KEY] = Errors.OKTA_OIDC_ERROR.errorMessage + //result[Constants.ERROR_MSG_KEY] = msg - PendingOperation.success(result) + PendingOperation.error(Errors.OKTA_OIDC_ERROR, Errors.OKTA_OIDC_ERROR.errorMessage,msg) } override fun onCancel() { - val result = mutableMapOf() - result[Constants.RESOLVE_TYPE_KEY] = Constants.CANCELLED - PendingOperation.success(result) + // val result = mutableMapOf() + // result[Constants.RESOLVE_TYPE_KEY] = Constants.CANCELLED + PendingOperation.error(Errors.CANCELLED_ERROR, Errors.CANCELLED_ERROR.errorMessage) } }, activity) } \ No newline at end of file diff --git a/lib/flutter_okta_sdk.dart b/lib/flutter_okta_sdk.dart index c08479f..124398f 100644 --- a/lib/flutter_okta_sdk.dart +++ b/lib/flutter_okta_sdk.dart @@ -1,3 +1,7 @@ +import 'dart:convert'; +import 'dart:io'; + +import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'BaseRequest.dart'; @@ -15,7 +19,7 @@ class OktaSDK { this.isInitialized = true; } - Future signIn() async { + Future signIn() async { if (this.isInitialized == false) { throw Exception("Cannot sign in before initializing Okta SDK"); } diff --git a/pubspec.yaml b/pubspec.yaml index 02606d5..fd40211 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: flutter_okta_sdk description: This library makes it easy to add authentication to flutter apps. This library is a wrapper around Okta OIDC Android and Okta OIDC iOS. -version: 1.0.0-dev.7 +version: 1.0.0-dev.8 homepage: https://github.com/sonikro/flutter-okta-sdk environment: From a4d28b0981cb1ee32472f44ad368815f26a3f053 Mon Sep 17 00:00:00 2001 From: Raymond Date: Tue, 8 Feb 2022 08:54:31 +1300 Subject: [PATCH 2/2] removed unused imports --- lib/flutter_okta_sdk.dart | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lib/flutter_okta_sdk.dart b/lib/flutter_okta_sdk.dart index 124398f..910e8cf 100644 --- a/lib/flutter_okta_sdk.dart +++ b/lib/flutter_okta_sdk.dart @@ -1,7 +1,3 @@ -import 'dart:convert'; -import 'dart:io'; - -import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'BaseRequest.dart';