Skip to content
Open
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 @@ -10,7 +10,7 @@ import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
import 'package:http/http.dart' as http;
import 'package:openid_client/openid_client.dart';
import 'package:uni_links/uni_links.dart' as uni_links;
import 'package:app_links/app_links.dart';
import 'package:universal_platform/universal_platform.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:url_launcher/url_launcher_string.dart';
Expand All @@ -23,9 +23,11 @@ class ApptiveGridAuthenticator {
this.httpClient,
AuthenticationStorage? authenticationStorage,
VoidCallback? onAuthenticationChanged,
AppLinks? appLinks,
}) {
_onAuthenticationChanged = onAuthenticationChanged;
_authenticationStorage = authenticationStorage;
_appLinks = appLinks ?? AppLinks();
performSetup();
}

Expand All @@ -46,22 +48,23 @@ class ApptiveGridAuthenticator {

late Completer _setupCompleter;

late AppLinks _appLinks;

/// Performs general Authenticator Setup tasks
/// like checking for saved credentials
/// and listening to authentication callbacks
Future<void> performSetup() async {
_setupCompleter = Completer();
if (!kIsWeb) {
_authCallbackSubscription?.cancel();
_authCallbackSubscription = uni_links.uriLinkStream
_authCallbackSubscription = _appLinks.uriLinkStream
.where(
(event) =>
event != null &&
event.scheme ==
client.options.authenticationOptions.redirectScheme
?.toLowerCase(),
client.options.authenticationOptions.redirectScheme
?.toLowerCase(),
)
.listen((event) => _handleAuthRedirect(event!));
.listen((event) => _handleAuthRedirect(event));
}

if (client.options.authenticationOptions.persistCredentials) {
Expand Down
3 changes: 1 addition & 2 deletions packages/apptive_grid_core/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ dependencies:
mime: ^1.0.4
provider: ^6.0.5
openid_client: ^0.4.7
uni_links: ^0.5.1
app_links: ^6.4.0
universal_file: ^1.0.0
universal_platform: ^1.0.0+1
url_launcher: ^6.1.10
Expand All @@ -30,7 +30,6 @@ dev_dependencies:
pedantic: ^1.11.1
mocktail: ^1.0.1
url_launcher_platform_interface: ^2.1.2
uni_links_platform_interface: ^1.0.0
plugin_platform_interface: ^2.1.4
flutter_secure_storage_platform_interface: ^1.0.1
flutter_test:
Expand Down
8 changes: 3 additions & 5 deletions packages/apptive_grid_core/test/api_client_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import 'package:flutter_test/flutter_test.dart';
import 'package:http/http.dart';
import 'package:mocktail/mocktail.dart';
import 'package:openid_client/openid_client.dart' show TokenResponse;
import 'package:uni_links_platform_interface/uni_links_platform_interface.dart';
import 'package:url_launcher_platform_interface/url_launcher_platform_interface.dart';

import 'authenticator_test.dart';
Expand Down Expand Up @@ -45,10 +44,9 @@ void main() {
});

setUp(() {
final mockUniLink = MockUniLinks();
UniLinksPlatform.instance = mockUniLink;
final stream = StreamController<String?>.broadcast();
when(() => mockUniLink.linkStream).thenAnswer((_) => stream.stream);
final mockAppLinks = MockAppLinks();
final stream = StreamController<Uri>.broadcast();
when(() => mockAppLinks.uriLinkStream).thenAnswer((_) => stream.stream);

authenticator = MockApptiveGridAuthenticator();
when(() => authenticator.checkAuthentication()).thenAnswer((_) async {});
Expand Down
Loading
Loading