Skip to content

Commit

Permalink
Version 3.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Bryant committed Feb 22, 2022
1 parent ad797e2 commit e0dddb6
Show file tree
Hide file tree
Showing 17 changed files with 33 additions and 40 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 3.0.0

- BREAKING: `isLoggedIn` now returns `Future<bool>` instead of bool

## 2.1.0

- Add pre-constructed `ClientTokenInterceptor` and `UserTokenInterceptor` to `Passputter`
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions lib/src/client_token_interceptor.dart
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
1 change: 0 additions & 1 deletion lib/src/in_memory_token_storage.dart
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion lib/src/passputter_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class PassputterImpl implements Passputter {
final String clientSecret;

@override
bool get isLoggedIn => tokenStorage.userToken != null;
Future<bool> get isLoggedIn async => (await tokenStorage.userToken) != null;

@override
Future<void> logIn({
Expand Down
2 changes: 1 addition & 1 deletion lib/src/passputter_interface.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ abstract class Passputter {
}

/// Whether the user is logged in.
bool get isLoggedIn;
Future<bool> get isLoggedIn;

/// Log in with the given [email] and [password] credentials.
///
Expand Down
2 changes: 2 additions & 0 deletions lib/src/token_expired_exception.dart
Original file line number Diff line number Diff line change
@@ -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(
Expand Down
2 changes: 1 addition & 1 deletion lib/src/token_storage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
5 changes: 2 additions & 3 deletions test/passputter_test.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
21 changes: 10 additions & 11 deletions test/src/client_token_interceptor_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}

Expand All @@ -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,
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 1 addition & 2 deletions test/src/in_memory_token_storage_test.dart
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
3 changes: 1 addition & 2 deletions test/src/oauth_api_impl_test.dart
Original file line number Diff line number Diff line change
@@ -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 {}

Expand Down
9 changes: 4 additions & 5 deletions test/src/oauth_token_test.dart
Original file line number Diff line number Diff line change
@@ -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', () {
Expand All @@ -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 = <String, dynamic>{
'access_token': 'token',
Expand All @@ -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 = <String, dynamic>{
'access_token': 'token',
Expand Down
4 changes: 1 addition & 3 deletions test/src/passputter_impl_test.dart
Original file line number Diff line number Diff line change
@@ -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 {}

Expand Down
3 changes: 1 addition & 2 deletions test/src/token_expired_exception_test.dart
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
6 changes: 2 additions & 4 deletions test/src/user_token_interceptor_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}

Expand Down

0 comments on commit e0dddb6

Please sign in to comment.