Skip to content

Commit

Permalink
Replaced callbacks onTokenExpiring and onTokenExpired by event types …
Browse files Browse the repository at this point in the history
…OidcTokenExpiringEvent/OidcTokenExpiredEvent
  • Loading branch information
akaegi committed Oct 13, 2024
1 parent cfe723d commit 5004c16
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 12 deletions.
8 changes: 6 additions & 2 deletions packages/oidc_core/lib/src/managers/user_manager_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,9 @@ abstract class OidcUserManagerBase {

@protected
Future<void> handleTokenExpiring(OidcToken event) async {
settings.onTokenExpiring?.call(event);
eventsController.add(
OidcTokenExpiringEvent.now(currentToken: event)
);

final refreshToken = event.refreshToken;
if (refreshToken == null) {
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 2 additions & 0 deletions packages/oidc_core/lib/src/models/events/_exports.dart
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
export 'event.dart';
export 'pre_logout_event.dart';
export 'token_expired_event.dart';
export 'token_expiring_event.dart';
18 changes: 18 additions & 0 deletions packages/oidc_core/lib/src/models/events/token_expired_event.dart
Original file line number Diff line number Diff line change
@@ -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;
}
18 changes: 18 additions & 0 deletions packages/oidc_core/lib/src/models/events/token_expiring_event.dart
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -37,8 +35,6 @@ class OidcUserManagerSettings {
this.sessionManagementSettings = const OidcSessionManagementSettings(),
this.getIdToken,
this.supportOfflineAuth = false,
this.onTokenExpiring,
this.onTokenExpired,
});

/// The default scopes
Expand Down Expand Up @@ -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;
}

///
Expand Down

0 comments on commit 5004c16

Please sign in to comment.