Skip to content

Commit

Permalink
feat: use clock package
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmednfwela committed Mar 19, 2024
1 parent 05f4db7 commit 157694d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
5 changes: 3 additions & 2 deletions lib/src/jwk.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/// [JSON Web Key](https://tools.ietf.org/html/rfc7517)
library jose.jwk;

import 'package:clock/clock.dart';
import 'dart:async';
import 'dart:async' as async show runZoned;
import 'dart:convert';
Expand Down Expand Up @@ -598,7 +599,7 @@ class DefaultJsonWebKeySetLoader extends JsonWebKeySetLoader {
case 'https':
case 'http':
var v = _cache[uri];
if (v != null && v.key.isAfter(DateTime.now())) {
if (v != null && v.key.isAfter(clock.now())) {
return v.value;
}
var r = await _httpClient.get(uri);
Expand Down Expand Up @@ -638,6 +639,6 @@ class DefaultJsonWebKeySetLoader extends JsonWebKeySetLoader {
}
}
}
return DateTime.now().add(delta);
return clock.now().add(delta);
}
}
4 changes: 3 additions & 1 deletion lib/src/jwt.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/// [JSON Web Token](https://tools.ietf.org/html/rfc7519)
library jose.jwt;

import 'package:clock/clock.dart';

import 'jose.dart';
import 'jwk.dart';
import 'util.dart';
Expand Down Expand Up @@ -69,7 +71,7 @@ class JsonWebTokenClaims extends JsonObject {
Uri? issuer,
String? clientId,
}) sync* {
final now = DateTime.now();
final now = clock.now();
final diff = now.difference(expiry!);
if (diff > expiryTolerance) {
yield JoseException(
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ dependencies:
http_parser: ^4.0.0
asn1lib: ^1.0.0
collection: ^1.14.13
clock: ^1.1.1

dev_dependencies:
test: ^1.24.4
Expand Down

0 comments on commit 157694d

Please sign in to comment.