Skip to content
This repository was archived by the owner on Dec 17, 2024. It is now read-only.
Draft
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 @@ -35,7 +35,7 @@ import com.onegini.mobile.sdk.flutter.useCases.GetRedirectUrlUseCase
import com.onegini.mobile.sdk.flutter.useCases.GetRegisteredAuthenticatorsUseCase
import com.onegini.mobile.sdk.flutter.useCases.GetUserProfilesUseCase
import com.onegini.mobile.sdk.flutter.useCases.HandleMobileAuthWithOtpUseCase
import com.onegini.mobile.sdk.flutter.useCases.HandleRegisteredUrlUseCase
import com.onegini.mobile.sdk.flutter.useCases.HandleRegistrationCallbackUseCase
import com.onegini.mobile.sdk.flutter.useCases.LogoutUseCase
import com.onegini.mobile.sdk.flutter.useCases.OtpAcceptAuthenticationRequestUseCase
import com.onegini.mobile.sdk.flutter.useCases.OtpDenyAuthenticationRequestUseCase
Expand Down Expand Up @@ -102,7 +102,7 @@ open class PigeonInterface : UserClientApi, ResourceMethodApi {
lateinit var getUserProfilesUseCase: GetUserProfilesUseCase

@Inject
lateinit var handleRegisteredUrlUseCase: HandleRegisteredUrlUseCase
lateinit var handleRegistrationCallbackUseCase: HandleRegistrationCallbackUseCase

@Inject
lateinit var logoutUseCase: LogoutUseCase
Expand Down Expand Up @@ -188,8 +188,8 @@ open class PigeonInterface : UserClientApi, ResourceMethodApi {
registrationUseCase(identityProviderId, scopes, callback)
}

override fun handleRegisteredUserUrl(url: String, signInType: Long, callback: (Result<Unit>) -> Unit) {
callback(handleRegisteredUrlUseCase(url, signInType))
override fun handleRegistrationCallback(url: String, callback: (Result<Unit>) -> Unit) {
callback(handleRegistrationCallbackUseCase(url))
}

override fun getIdentityProviders(callback: (Result<List<OWIdentityProvider>>) -> Unit) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,29 @@ package com.onegini.mobile.sdk.flutter.handlers
import android.net.Uri
import com.onegini.mobile.sdk.android.handlers.request.OneginiBrowserRegistrationRequestHandler
import com.onegini.mobile.sdk.android.handlers.request.callback.OneginiBrowserRegistrationCallback
import com.onegini.mobile.sdk.flutter.OneWelcomeWrapperErrors.*
import com.onegini.mobile.sdk.flutter.helpers.SdkError
import com.onegini.mobile.sdk.flutter.pigeonPlugin.NativeCallFlutterApi
import javax.inject.Inject
import javax.inject.Singleton

// TODO Put functions into use cases; https://onewelcome.atlassian.net/browse/FP-35
@Singleton
class BrowserRegistrationRequestHandler @Inject constructor(private val nativeApi: NativeCallFlutterApi) :
OneginiBrowserRegistrationRequestHandler {
private var callback: OneginiBrowserRegistrationCallback? = null

companion object {
var callback: OneginiBrowserRegistrationCallback? = null
fun handleRegistrationCallback(uri: Uri): Result<Unit> {
return callback?.let {
it.handleRegistrationCallback(uri)
Result.success(Unit)
} ?: Result.failure(SdkError(BROWSER_REGISTRATION_NOT_IN_PROGRESS).pigeonError())
}

/**
* Finish registration action with result from web browser
* TODO: Move this to use-case after browser logic rework
* https://onewelcome.atlassian.net/browse/FP-35
*/
fun handleRegistrationCallback(uri: Uri) {
if (callback != null) {
callback?.handleRegistrationCallback(uri)
callback = null
}
}
fun cancelRegistration(): Result<Unit> {
return callback?.let {
it.denyRegistration()
Result.success(Unit)
} ?: Result.failure(SdkError(BROWSER_REGISTRATION_NOT_IN_PROGRESS).pigeonError())
}

override fun startRegistration(uri: Uri, oneginiBrowserRegistrationCallback: OneginiBrowserRegistrationCallback) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ private object UserClientApiCodec : StandardMessageCodec() {
interface UserClientApi {
fun startApplication(securityControllerClassName: String?, configModelClassName: String?, customIdentityProviderConfigs: List<OWCustomIdentityProvider>?, connectionTimeout: Long?, readTimeout: Long?, callback: (Result<Unit>) -> Unit)
fun registerUser(identityProviderId: String?, scopes: List<String>?, callback: (Result<OWRegistrationResponse>) -> Unit)
fun handleRegisteredUserUrl(url: String, signInType: Long, callback: (Result<Unit>) -> Unit)
fun handleRegistrationCallback(url: String, callback: (Result<Unit>) -> Unit)
fun getIdentityProviders(callback: (Result<List<OWIdentityProvider>>) -> Unit)
fun deregisterUser(profileId: String, callback: (Result<Unit>) -> Unit)
fun getRegisteredAuthenticators(profileId: String, callback: (Result<List<OWAuthenticator>>) -> Unit)
Expand Down Expand Up @@ -517,13 +517,12 @@ interface UserClientApi {
}
}
run {
val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.UserClientApi.handleRegisteredUserUrl", codec)
val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.UserClientApi.handleRegistrationCallback", codec)
if (api != null) {
channel.setMessageHandler { message, reply ->
val args = message as List<Any?>
val urlArg = args[0] as String
val signInTypeArg = args[1].let { if (it is Int) it.toLong() else it as Long }
api.handleRegisteredUserUrl(urlArg, signInTypeArg) { result: Result<Unit> ->
api.handleRegistrationCallback(urlArg) { result: Result<Unit> ->
val error = result.exceptionOrNull()
if (error != null) {
reply.reply(wrapError(error))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,10 @@
package com.onegini.mobile.sdk.flutter.useCases

import com.onegini.mobile.sdk.flutter.handlers.BrowserRegistrationRequestHandler
import com.onegini.mobile.sdk.flutter.helpers.SdkError
import com.onegini.mobile.sdk.flutter.OneWelcomeWrapperErrors.BROWSER_REGISTRATION_NOT_IN_PROGRESS
import javax.inject.Inject

class CancelBrowserRegistrationUseCase @Inject constructor() {
class CancelBrowserRegistrationUseCase @Inject constructor(private val browserRegistrationRequestHandler: BrowserRegistrationRequestHandler) {
operator fun invoke(): Result<Unit> {
return when (val browserCallback = BrowserRegistrationRequestHandler.callback) {
null -> Result.failure(SdkError(BROWSER_REGISTRATION_NOT_IN_PROGRESS).pigeonError())
else -> {
browserCallback.denyRegistration()
BrowserRegistrationRequestHandler.callback = null
Result.success(Unit)
}
}
return browserRegistrationRequestHandler.cancelRegistration()
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.onegini.mobile.sdk.flutter.useCases

import com.onegini.mobile.sdk.flutter.facade.UriFacade
import com.onegini.mobile.sdk.flutter.handlers.BrowserRegistrationRequestHandler
import javax.inject.Inject
import javax.inject.Singleton

@Singleton
class HandleRegistrationCallbackUseCase @Inject constructor(private val uriFacade: UriFacade, private val registrationRequestHandler: BrowserRegistrationRequestHandler) {
operator fun invoke(url: String): Result<Unit> {
val uri = uriFacade.parse(url)
return registrationRequestHandler.handleRegistrationCallback(uri)
}
}
18 changes: 10 additions & 8 deletions example/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@
android:name="${applicationName}"
android:icon="@mipmap/ic_launcher"
android:label="onegini_example">
<activity
android:name="com.linusu.flutter_web_auth_2.CallbackActivity"
android:exported="true">
<intent-filter android:label="flutter_web_auth_2">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="oneginiexample" />
</intent-filter>
</activity>
<activity
android:exported="true"
android:name="com.onegini.mobile.onegini_example.MainActivity"
Expand Down Expand Up @@ -37,14 +47,6 @@
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />

<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />

<data android:scheme="oneginiexample" />
</intent-filter>
</activity>
<!-- Don't delete the meta-data below.
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,5 @@
package com.onegini.mobile.onegini_example

import android.content.Intent
import com.onegini.mobile.sdk.flutter.handlers.BrowserRegistrationRequestHandler
import io.flutter.embedding.android.FlutterActivity

class MainActivity : FlutterActivity() {

override fun onNewIntent(intent: Intent) {
super.onNewIntent(intent)
if (intent.data != null) {
// TODO: Move this logic to outside of the SDK
// https://onewelcome.atlassian.net/browse/FP-35
BrowserRegistrationRequestHandler.handleRegistrationCallback(intent.data!!)
}
}
}
class MainActivity : FlutterActivity()
6 changes: 6 additions & 0 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ PODS:
- AFNetworking/UIKit (4.0.1):
- AFNetworking/NSURLSession
- Flutter (1.0.0)
- flutter_web_auth_2 (1.1.1):
- Flutter
- fluttertoast (0.0.2):
- Flutter
- Toast
Expand Down Expand Up @@ -43,6 +45,7 @@ PODS:

DEPENDENCIES:
- Flutter (from `Flutter`)
- flutter_web_auth_2 (from `.symlinks/plugins/flutter_web_auth_2/ios`)
- fluttertoast (from `.symlinks/plugins/fluttertoast/ios`)
- onegini (from `.symlinks/plugins/onegini/ios`)
- qr_code_scanner (from `.symlinks/plugins/qr_code_scanner/ios`)
Expand All @@ -62,6 +65,8 @@ SPEC REPOS:
EXTERNAL SOURCES:
Flutter:
:path: Flutter
flutter_web_auth_2:
:path: ".symlinks/plugins/flutter_web_auth_2/ios"
fluttertoast:
:path: ".symlinks/plugins/fluttertoast/ios"
onegini:
Expand All @@ -74,6 +79,7 @@ EXTERNAL SOURCES:
SPEC CHECKSUMS:
AFNetworking: 3bd23d814e976cd148d7d44c3ab78017b744cd58
Flutter: f04841e97a9d0b0a8025694d0796dd46242b2854
flutter_web_auth_2: a1bc00762c408a8f80b72a538cd7ff5b601c3e71
fluttertoast: eb263d302cc92e04176c053d2385237e9f43fad0
MTBBarcodeScanner: f453b33c4b7dfe545d8c6484ed744d55671788cb
onegini: bcef895403897119a1f340413bc75b8c1328624c
Expand Down
6 changes: 0 additions & 6 deletions example/ios/Runner/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,4 @@ import OneginiSDKiOS
GeneratedPluginRegistrant.register(with: self)
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}

override func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool {
let isOneginiUrlCallback: Bool = OneginiModuleSwift.sharedInstance.handleDeepLinkCallbackUrl(url)
debugPrint(isOneginiUrlCallback)
return true
}
}
15 changes: 13 additions & 2 deletions example/lib/onegini_listener.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_web_auth_2/flutter_web_auth_2.dart';
import 'package:onegini/callbacks/onegini_registration_callback.dart';
import 'package:onegini/model/authentication_attempt.dart';
import 'package:onegini/model/onegini_event.dart';
import 'package:onegini/onegini.dart';
Expand Down Expand Up @@ -171,8 +173,17 @@ class OneginiListener extends OneginiEventListener {

@override
void handleRegisteredUrl(BuildContext buildContext, String url) async {
await Onegini.instance.userClient.handleRegisteredUserUrl(buildContext, url,
signInType: WebSignInType.insideApp);
try {
final result = await FlutterWebAuth2.authenticate(
url: url, callbackUrlScheme: "oneginiexample");
print(result);
Onegini.instance.userClient
.handleRegistrationCallback(buildContext, result);
} catch (err) {
print(err);
showFlutterToast(err.toString());
OneginiRegistrationCallback().cancelBrowserRegistration();
}
}

@override
Expand Down
1 change: 1 addition & 0 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ dependencies:
fluttertoast: ^8.0.9
qr_code_scanner: ^1.0.1
url_launcher: ^6.0.3
flutter_web_auth_2: ^2.1.2

dev_dependencies:
flutter_test:
Expand Down
Loading