Skip to content

Commit ad797e2

Browse files
author
Peter Bryant
committed
Provide pre-constructed token interceptors from Passputter instances
1 parent be77d85 commit ad797e2

File tree

5 files changed

+36
-3
lines changed

5 files changed

+36
-3
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 2.1.0
2+
3+
- Add pre-constructed `ClientTokenInterceptor` and `UserTokenInterceptor` to `Passputter`
4+
15
## 2.0.1
26

37
- Fix build

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Easily authenticate using OAuth 2.0 client/password grants.
1414
Install passputter from [pub.dev](https://pub.dev/packages/passputter):
1515

1616
```yaml
17-
passputter: ^2.0.1
17+
passputter: ^2.1.0
1818
```
1919
2020
## ✅ Prerequisites
@@ -128,6 +128,14 @@ Passputter provides two interceptors which you can add to your Dio instances: `U
128128

129129
`ClientTokenInterceptor` will add a client token to all requests. If no token is saved in your `TokenStorage`, the interceptor will attempt to generate one before continuing.
130130

131+
You can retrieve them from your `Passputter` instance:
132+
133+
```dart
134+
dio.interceptors.add(passputter.clientTokenInterceptor);
135+
// or
136+
dio.interceptors.add(passputter.userTokenInterceptor);
137+
```
138+
131139
### 💰 Step 4: Profit
132140

133141
That's it! You now have a fully working authentication system for your Flutter app.

lib/src/passputter_impl.dart

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,20 @@ class PassputterImpl implements Passputter {
4646
Future<void> logOut() async {
4747
await tokenStorage.deleteUserToken();
4848
}
49+
50+
@override
51+
ClientTokenInterceptor get clientTokenInterceptor => ClientTokenInterceptor(
52+
tokenStorage: tokenStorage,
53+
oAuthApi: oAuthApi,
54+
clientId: clientId,
55+
clientSecret: clientSecret,
56+
);
57+
58+
@override
59+
UserTokenInterceptor get userTokenInterceptor => UserTokenInterceptor(
60+
tokenStorage: tokenStorage,
61+
oAuthApi: oAuthApi,
62+
clientId: clientId,
63+
clientSecret: clientSecret,
64+
);
4965
}

lib/src/passputter_interface.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// 📦 Package imports:
22
import 'package:dio/dio.dart';
3-
43
// 🌎 Project imports:
54
import 'package:passputter/passputter.dart';
65
import 'package:passputter/src/oauth_api_impl.dart';
@@ -51,4 +50,10 @@ abstract class Passputter {
5150

5251
/// Log out of the application
5352
Future<void> logOut();
53+
54+
/// A [Dio] interceptor which adds a client token to each request
55+
ClientTokenInterceptor get clientTokenInterceptor;
56+
57+
/// A [Dio] interceptor which adds a user token to each request
58+
UserTokenInterceptor get userTokenInterceptor;
5459
}

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: passputter
22
description: Easily authenticate using OAuth 2.0 client/password grants.
3-
version: 2.0.1
3+
version: 2.1.0
44
repository: https://github.com/netsells/passputter
55

66
environment:

0 commit comments

Comments
 (0)