@@ -9,7 +9,8 @@ import 'package:oauth_chopper/src/oauth_token.dart';
99import 'package:oauth_chopper/src/storage/memory_storage.dart' ;
1010import 'package:oauth_chopper/src/storage/oauth_storage.dart' ;
1111
12- /// OAuthChopper client for configuring OAuth authentication with [Chopper] .
12+ /// {@template oauth_chopper}
13+ /// OAuthChopper client for configuring OAuth authentication with Chopper.
1314///
1415/// For example:
1516/// ```dart
@@ -19,7 +20,23 @@ import 'package:oauth_chopper/src/storage/oauth_storage.dart';
1920/// secret: secret,
2021/// );
2122/// ```
23+ /// {@endtemplate}
2224class OAuthChopper {
25+ /// {@macro oauth_chopper}
26+ OAuthChopper ({
27+ required this .authorizationEndpoint,
28+ required this .identifier,
29+ required this .secret,
30+ this .endSessionEndpoint,
31+ this .httpClient,
32+
33+ /// OAuth storage for storing credentials.
34+ /// By default it will use a in memory storage [MemoryStorage] .
35+ /// For persisting the credentials implement a custom [OAuthStorage] .
36+ /// See [OAuthStorage] for more information.
37+ OAuthStorage ? storage,
38+ }) : _storage = storage ?? MemoryStorage ();
39+
2340 /// OAuth authorization endpoint.
2441 final Uri authorizationEndpoint;
2542
@@ -33,36 +50,24 @@ class OAuthChopper {
3350 final String secret;
3451
3552 /// OAuth storage for storing credentials.
36- /// By default it will use a in memory storage. For persisting the credentials implement a custom [OAuthStorage] .
53+ /// By default it will use a in memory storage. For persisting the credentials
54+ /// implement a custom [OAuthStorage] .
3755 /// See [OAuthStorage] for more information.
3856 final OAuthStorage _storage;
3957
4058 /// Provide a custom [http.Client] which will be passed to [oauth2] and used for making new requests.
4159 final http.Client ? httpClient;
4260
43- OAuthChopper ({
44- required this .authorizationEndpoint,
45- required this .identifier,
46- required this .secret,
47- this .endSessionEndpoint,
48- this .httpClient,
49-
50- /// OAuth storage for storing credentials.
51- /// By default it will use a in memory storage [MemoryStorage] . For persisting the credentials implement a custom [OAuthStorage] .
52- /// See [OAuthStorage] for more information.
53- OAuthStorage ? storage,
54- }) : _storage = storage ?? MemoryStorage ();
55-
5661 /// Get stored [OAuthToken] .
5762 Future <OAuthToken ?> get token async {
5863 final credentialsJson = await _storage.fetchCredentials ();
59- return credentialsJson != null
60- ? OAuthToken .fromJson (credentialsJson)
61- : null ;
64+ return credentialsJson != null ? OAuthToken .fromJson (credentialsJson) : null ;
6265 }
6366
6467 /// Provides an [OAuthAuthenticator] instance.
65- /// The authenticator can throw exceptions when OAuth authentication fails. If [onError] is provided exceptions will be passed to [onError] and not be thrown.
68+ /// The authenticator can throw exceptions when OAuth authentication fails.
69+ /// If [onError] is provided exceptions will be passed to [onError] and not be
70+ /// thrown.
6671 OAuthAuthenticator authenticator ({
6772 /// When provided [onError] handles exceptions if thrown.
6873 OnErrorCallback ? onError,
@@ -72,10 +77,12 @@ class OAuthChopper {
7277 /// Provides an [OAuthInterceptor] instance.
7378 OAuthInterceptor get interceptor => OAuthInterceptor (this );
7479
75- /// Tries to refresh the available credentials and returns a new [OAuthToken] instance.
76- /// Throws an exception when refreshing fails. If the exception is a [AuthorizationException] it clears the storage.
80+ /// Tries to refresh the available credentials and returns a new [OAuthToken]
81+ /// instance.
82+ /// Throws an exception when refreshing fails. If the exception is a
83+ /// [AuthorizationException] it clears the storage.
7784 /// See [Credentials.refresh]
78- Future <OAuthToken ?> refresh () async {
85+ Future <OAuthToken ?> refresh () async {
7986 final credentialsJson = await _storage.fetchCredentials ();
8087 if (credentialsJson == null ) return null ;
8188 final credentials = oauth2.Credentials .fromJson (credentialsJson);
@@ -93,15 +100,17 @@ class OAuthChopper {
93100 }
94101 }
95102
96- /// Request an [OAuthGrant] and stores the credentials in the [storage] .
103+ /// Request an [OAuthGrant] and stores the credentials in the
104+ /// [_storage] .
105+ ///
97106 /// Currently supported grants:
98107 /// - [ResourceOwnerPasswordGrant]
99108 /// - [ClientCredentialsGrant]
100109 /// - [AuthorizationCodeGrant]
101110 /// Throws an exception if the grant fails.
102111 Future <OAuthToken > requestGrant (OAuthGrant grant) async {
103112 final credentials = await grant.handle (
104- authorizationEndpoint, identifier, secret, httpClient);
113+ authorizationEndpoint, identifier, secret, httpClient, );
105114
106115 await _storage.saveCredentials (credentials);
107116
0 commit comments