diff --git a/packages/oidc_core/lib/src/managers/user_manager_base.dart b/packages/oidc_core/lib/src/managers/user_manager_base.dart index 80a7d28..2395578 100644 --- a/packages/oidc_core/lib/src/managers/user_manager_base.dart +++ b/packages/oidc_core/lib/src/managers/user_manager_base.dart @@ -794,7 +794,9 @@ abstract class OidcUserManagerBase { @protected Future handleTokenExpiring(OidcToken event) async { - settings.onTokenExpiring?.call(event); + eventsController.add( + OidcTokenExpiringEvent.now(currentToken: event) + ); final refreshToken = event.refreshToken; if (refreshToken == null) { @@ -836,7 +838,9 @@ abstract class OidcUserManagerBase { @protected void handleTokenExpired(OidcToken event) { - settings.onTokenExpired?.call(event); + eventsController.add( + OidcTokenExpiredEvent.now(currentToken: event), + ); if (!settings.supportOfflineAuth) { forgetUser(); diff --git a/packages/oidc_core/lib/src/models/events/_exports.dart b/packages/oidc_core/lib/src/models/events/_exports.dart index 432099d..a3ee669 100644 --- a/packages/oidc_core/lib/src/models/events/_exports.dart +++ b/packages/oidc_core/lib/src/models/events/_exports.dart @@ -1,2 +1,4 @@ export 'event.dart'; export 'pre_logout_event.dart'; +export 'token_expired_event.dart'; +export 'token_expiring_event.dart'; diff --git a/packages/oidc_core/lib/src/models/events/token_expired_event.dart b/packages/oidc_core/lib/src/models/events/token_expired_event.dart new file mode 100644 index 0000000..3eba93f --- /dev/null +++ b/packages/oidc_core/lib/src/models/events/token_expired_event.dart @@ -0,0 +1,18 @@ +import 'package:oidc_core/oidc_core.dart'; + +/// An event that gets raised after a token expired. +class OidcTokenExpiredEvent extends OidcEvent { + /// + const OidcTokenExpiredEvent({ + required this.currentToken, + required super.at, + }); + + /// + OidcTokenExpiredEvent.now({ + required this.currentToken, + }) : super.now(); + + /// The current token that is expired. + final OidcToken currentToken; +} diff --git a/packages/oidc_core/lib/src/models/events/token_expiring_event.dart b/packages/oidc_core/lib/src/models/events/token_expiring_event.dart new file mode 100644 index 0000000..7656632 --- /dev/null +++ b/packages/oidc_core/lib/src/models/events/token_expiring_event.dart @@ -0,0 +1,18 @@ +import 'package:oidc_core/oidc_core.dart'; + +/// An event that gets raised before a token expires. +class OidcTokenExpiringEvent extends OidcEvent { + /// + const OidcTokenExpiringEvent({ + required this.currentToken, + required super.at, + }); + + /// + OidcTokenExpiringEvent.now({ + required this.currentToken, + }) : super.now(); + + /// The current token that is expiring. + final OidcToken currentToken; +} diff --git a/packages/oidc_core/lib/src/models/settings/user_manager_settings.dart b/packages/oidc_core/lib/src/models/settings/user_manager_settings.dart index 4f056e9..f4c820e 100644 --- a/packages/oidc_core/lib/src/models/settings/user_manager_settings.dart +++ b/packages/oidc_core/lib/src/models/settings/user_manager_settings.dart @@ -3,8 +3,6 @@ import 'package:oidc_core/oidc_core.dart'; /// The callback used to determine the `expiring` duration. typedef OidcRefreshBeforeCallback = Duration? Function(OidcToken token); -typedef OidcTokenCallback = void Function(OidcToken token); - /// The default refreshBefore function, which refreshes 1 minute before the token expires. Duration? defaultRefreshBefore(OidcToken token) { return const Duration(minutes: 1); @@ -37,8 +35,6 @@ class OidcUserManagerSettings { this.sessionManagementSettings = const OidcSessionManagementSettings(), this.getIdToken, this.supportOfflineAuth = false, - this.onTokenExpiring, - this.onTokenExpired, }); /// The default scopes @@ -131,12 +127,6 @@ class OidcUserManagerSettings { /// platform-specific options. final OidcPlatformSpecificOptions? options; - - /// Callback that is called before the token expires. - final OidcTokenCallback? onTokenExpiring; - - /// Callback that is called after the token expired. - final OidcTokenCallback? onTokenExpired; } ///