diff --git a/CHANGELOG.md b/CHANGELOG.md index 50ffa3b..f5a31dd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 3.0.0 + +- BREAKING: `isLoggedIn` now returns `Future` instead of bool + ## 2.1.0 - Add pre-constructed `ClientTokenInterceptor` and `UserTokenInterceptor` to `Passputter` diff --git a/README.md b/README.md index c97b591..471061f 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ Easily authenticate using OAuth 2.0 client/password grants. Install passputter from [pub.dev](https://pub.dev/packages/passputter): ```yaml -passputter: ^2.1.0 +passputter: ^3.0.0 ``` ## ✅ Prerequisites diff --git a/lib/src/client_token_interceptor.dart b/lib/src/client_token_interceptor.dart index 43f79e3..e37a95d 100644 --- a/lib/src/client_token_interceptor.dart +++ b/lib/src/client_token_interceptor.dart @@ -1,11 +1,9 @@ // 📦 Package imports: import 'package:clock/clock.dart'; import 'package:dio/dio.dart'; - // 🌎 Project imports: import 'package:passputter/passputter.dart'; import 'package:passputter/src/oauth_api_interface.dart'; -import 'package:passputter/src/oauth_token.dart'; /// Adds a client bearer token to the Authorization header of each request class ClientTokenInterceptor extends Interceptor { diff --git a/lib/src/in_memory_token_storage.dart b/lib/src/in_memory_token_storage.dart index 95253ac..3452ef1 100644 --- a/lib/src/in_memory_token_storage.dart +++ b/lib/src/in_memory_token_storage.dart @@ -1,6 +1,5 @@ // 🌎 Project imports: import 'package:passputter/passputter.dart'; -import 'package:passputter/src/oauth_token.dart'; /// Implementation of [TokenStorage] which stores tokens in memory. class InMemoryTokenStorage implements TokenStorage { diff --git a/lib/src/passputter_impl.dart b/lib/src/passputter_impl.dart index f303a8d..b9faa4e 100644 --- a/lib/src/passputter_impl.dart +++ b/lib/src/passputter_impl.dart @@ -25,7 +25,7 @@ class PassputterImpl implements Passputter { final String clientSecret; @override - bool get isLoggedIn => tokenStorage.userToken != null; + Future get isLoggedIn async => (await tokenStorage.userToken) != null; @override Future logIn({ diff --git a/lib/src/passputter_interface.dart b/lib/src/passputter_interface.dart index bcf7161..4ba7848 100644 --- a/lib/src/passputter_interface.dart +++ b/lib/src/passputter_interface.dart @@ -38,7 +38,7 @@ abstract class Passputter { } /// Whether the user is logged in. - bool get isLoggedIn; + Future get isLoggedIn; /// Log in with the given [email] and [password] credentials. /// diff --git a/lib/src/token_expired_exception.dart b/lib/src/token_expired_exception.dart index 07be17f..72e3404 100644 --- a/lib/src/token_expired_exception.dart +++ b/lib/src/token_expired_exception.dart @@ -1,7 +1,9 @@ // 🌎 Project imports: +import 'package:meta/meta.dart'; import 'package:passputter/src/oauth_token.dart'; /// Thrown when an expired [OAuthToken] is used and cannot be refreshed. +@immutable class TokenExpiredException implements Exception { /// Constructs a [TokenExpiredException] const TokenExpiredException( diff --git a/lib/src/token_storage.dart b/lib/src/token_storage.dart index f4ac888..dbe631a 100644 --- a/lib/src/token_storage.dart +++ b/lib/src/token_storage.dart @@ -2,7 +2,7 @@ import 'dart:async'; // 🌎 Project imports: -import 'oauth_token.dart'; +import 'package:passputter/src/oauth_token.dart'; /// Handles storage and retrieval of [OAuthToken]s. abstract class TokenStorage { diff --git a/pubspec.yaml b/pubspec.yaml index 726e5a0..fde8d7c 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: passputter description: Easily authenticate using OAuth 2.0 client/password grants. -version: 2.1.0 +version: 3.0.0 repository: https://github.com/netsells/passputter environment: diff --git a/test/passputter_test.dart b/test/passputter_test.dart index 31bf2fe..35d0f20 100644 --- a/test/passputter_test.dart +++ b/test/passputter_test.dart @@ -1,11 +1,10 @@ // 📦 Package imports: import 'package:dio/dio.dart'; import 'package:mock_web_server/mock_web_server.dart'; -import 'package:pretty_dio_logger/pretty_dio_logger.dart'; -import 'package:test/test.dart'; - // 🌎 Project imports: import 'package:passputter/passputter.dart'; +import 'package:pretty_dio_logger/pretty_dio_logger.dart'; +import 'package:test/test.dart'; void main() { const clientId = 'id'; diff --git a/test/src/client_token_interceptor_test.dart b/test/src/client_token_interceptor_test.dart index 4bdecd0..124e395 100644 --- a/test/src/client_token_interceptor_test.dart +++ b/test/src/client_token_interceptor_test.dart @@ -2,14 +2,11 @@ import 'package:clock/clock.dart'; import 'package:dio/dio.dart'; import 'package:mocktail/mocktail.dart'; -import 'package:test/test.dart'; -import 'package:time/time.dart'; - // 🌎 Project imports: import 'package:passputter/passputter.dart'; -import 'package:passputter/src/client_token_interceptor.dart'; import 'package:passputter/src/oauth_api_interface.dart'; -import 'package:passputter/src/oauth_token.dart'; +import 'package:test/test.dart'; +import 'package:time/time.dart'; class MockOAuthApi extends Mock implements OAuthApiInterface {} @@ -26,7 +23,7 @@ void main() { tokenStorage = InMemoryTokenStorage(); oAuthApi = MockOAuthApi(); handler = MockHandler(); - clock = Clock.fixed(DateTime(2021, 5, 1)); + clock = Clock.fixed(DateTime(2021, 5)); interceptor = ClientTokenInterceptor( tokenStorage: tokenStorage, oAuthApi: oAuthApi, @@ -74,11 +71,13 @@ void main() { }); test('generates header when token in TokenStorage has expired', () async { - await tokenStorage.saveClientToken(OAuthToken( - token: 'expired', - expiresAt: clock.now().subtract(1.hours), - refreshToken: null, - )); + await tokenStorage.saveClientToken( + OAuthToken( + token: 'expired', + expiresAt: clock.now().subtract(1.hours), + refreshToken: null, + ), + ); when(() => oAuthApi.getClientToken(clientId: 'id', clientSecret: 'secret')) .thenAnswer((_) async => token); diff --git a/test/src/in_memory_token_storage_test.dart b/test/src/in_memory_token_storage_test.dart index ae3cb81..3d9a1ad 100644 --- a/test/src/in_memory_token_storage_test.dart +++ b/test/src/in_memory_token_storage_test.dart @@ -1,9 +1,8 @@ // 📦 Package imports: -import 'package:test/test.dart'; - // 🌎 Project imports: import 'package:passputter/src/in_memory_token_storage.dart'; import 'package:passputter/src/oauth_token.dart'; +import 'package:test/test.dart'; void main() { late InMemoryTokenStorage storage; diff --git a/test/src/oauth_api_impl_test.dart b/test/src/oauth_api_impl_test.dart index 3775b1a..d3bcf82 100644 --- a/test/src/oauth_api_impl_test.dart +++ b/test/src/oauth_api_impl_test.dart @@ -1,11 +1,10 @@ // 📦 Package imports: import 'package:dio/dio.dart'; import 'package:mocktail/mocktail.dart'; -import 'package:test/test.dart'; - // 🌎 Project imports: import 'package:passputter/src/oauth_api_impl.dart'; import 'package:passputter/src/oauth_token.dart'; +import 'package:test/test.dart'; class MockDio extends Mock implements Dio {} diff --git a/test/src/oauth_token_test.dart b/test/src/oauth_token_test.dart index cb01e18..fb9a23a 100644 --- a/test/src/oauth_token_test.dart +++ b/test/src/oauth_token_test.dart @@ -1,10 +1,9 @@ // 📦 Package imports: import 'package:clock/clock.dart'; -import 'package:test/test.dart'; -import 'package:time/time.dart'; - // 🌎 Project imports: import 'package:passputter/src/oauth_token.dart'; +import 'package:test/test.dart'; +import 'package:time/time.dart'; void main() { group('fromMap', () { @@ -24,7 +23,7 @@ void main() { }); test('without refresh token parses successfully', () { - final clock = Clock.fixed(DateTime(2021, 5, 1)); + final clock = Clock.fixed(DateTime(2021, 5)); final map = { 'access_token': 'token', @@ -41,7 +40,7 @@ void main() { }); test('with all arguments parses successfully', () { - final clock = Clock.fixed(DateTime(2021, 5, 1)); + final clock = Clock.fixed(DateTime(2021, 5)); final map = { 'access_token': 'token', diff --git a/test/src/passputter_impl_test.dart b/test/src/passputter_impl_test.dart index 650a002..a6420a5 100644 --- a/test/src/passputter_impl_test.dart +++ b/test/src/passputter_impl_test.dart @@ -1,12 +1,10 @@ // 📦 Package imports: import 'package:mocktail/mocktail.dart'; -import 'package:test/test.dart'; - // 🌎 Project imports: import 'package:passputter/passputter.dart'; import 'package:passputter/src/oauth_api_interface.dart'; -import 'package:passputter/src/oauth_token.dart'; import 'package:passputter/src/passputter_impl.dart'; +import 'package:test/test.dart'; class MockOAuthApi extends Mock implements OAuthApiInterface {} diff --git a/test/src/token_expired_exception_test.dart b/test/src/token_expired_exception_test.dart index 360caef..ca08467 100644 --- a/test/src/token_expired_exception_test.dart +++ b/test/src/token_expired_exception_test.dart @@ -1,9 +1,8 @@ // 📦 Package imports: -import 'package:test/test.dart'; - // 🌎 Project imports: import 'package:passputter/src/oauth_token.dart'; import 'package:passputter/src/token_expired_exception.dart'; +import 'package:test/test.dart'; void main() { test('equal exceptions are evaluated as equal', () async { diff --git a/test/src/user_token_interceptor_test.dart b/test/src/user_token_interceptor_test.dart index 03988ab..9497dba 100644 --- a/test/src/user_token_interceptor_test.dart +++ b/test/src/user_token_interceptor_test.dart @@ -2,14 +2,12 @@ import 'package:clock/clock.dart'; import 'package:dio/dio.dart'; import 'package:mocktail/mocktail.dart'; -import 'package:test/test.dart'; -import 'package:time/time.dart'; - // 🌎 Project imports: import 'package:passputter/passputter.dart'; import 'package:passputter/src/oauth_api_interface.dart'; -import 'package:passputter/src/oauth_token.dart'; import 'package:passputter/src/token_expired_exception.dart'; +import 'package:test/test.dart'; +import 'package:time/time.dart'; class MockOAuthApi extends Mock implements OAuthApiInterface {}