Skip to content

Commit 176116a

Browse files
committed
Fixed dart formating
1 parent 3bafdca commit 176116a

File tree

8 files changed

+65
-28
lines changed

8 files changed

+65
-28
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 0.0.2
2+
3+
- Fixed dart formatting
4+
5+
16
## 0.0.1
27

38
- Initial version.

lib/src/oauth_authenticator.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ class OAuthAuthenticator extends Authenticator {
1717
final OAuthChopper oauthChopper;
1818

1919
@override
20-
FutureOr<Request?> authenticate(Request request, Response<dynamic> response, [Request? originalRequest]) async {
20+
FutureOr<Request?> authenticate(Request request, Response<dynamic> response,
21+
[Request? originalRequest]) async {
2122
final token = await oauthChopper.token;
2223
if (response.statusCode == HttpStatus.unauthorized && token != null) {
2324
try {

lib/src/oauth_chopper.dart

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ class OAuthChopper {
4747
/// Get stored [OAuthToken].
4848
Future<OAuthToken?> get token async {
4949
final credentialsJson = await _storage.fetchCredentials();
50-
return credentialsJson != null ? OAuthToken.fromJson(credentialsJson) : null;
50+
return credentialsJson != null
51+
? OAuthToken.fromJson(credentialsJson)
52+
: null;
5153
}
5254

5355
/// Provides an [OAuthAuthenticator] instance.
@@ -68,7 +70,8 @@ class OAuthChopper {
6870
if (credentialsJson == null) return null;
6971
final credentials = Credentials.fromJson(credentialsJson);
7072
try {
71-
final newCredentials = await credentials.refresh(identifier: identifier, secret: secret);
73+
final newCredentials =
74+
await credentials.refresh(identifier: identifier, secret: secret);
7275
await _storage.saveCredentials(newCredentials.toJson());
7376
return OAuthToken.fromCredentials(newCredentials);
7477
} catch (e) {
@@ -84,7 +87,8 @@ class OAuthChopper {
8487
///
8588
/// Throws an exception if the grant fails.
8689
Future<OAuthToken> requestGrant(OAuthGrant grant) async {
87-
final credentials = await grant.handle(authorizationEndpoint, identifier, secret);
90+
final credentials =
91+
await grant.handle(authorizationEndpoint, identifier, secret);
8892

8993
await _storage.saveCredentials(credentials);
9094

lib/src/oauth_grant.dart

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,21 @@ import 'package:oauth2/oauth2.dart' as oauth;
33
abstract class OAuthGrant {
44
const OAuthGrant();
55

6-
Future<String> handle(Uri authorizationEndpoint, String identifier, String secret);
6+
Future<String> handle(
7+
Uri authorizationEndpoint, String identifier, String secret);
78
}
89

910
/// Obtains credentials using a [resource owner password grant](https://tools.ietf.org/html/rfc6749#section-1.3.3).
1011
class ResourceOwnerPasswordGrant extends OAuthGrant {
1112
final String username;
1213
final String password;
1314

14-
const ResourceOwnerPasswordGrant({required this.username, required this.password});
15+
const ResourceOwnerPasswordGrant(
16+
{required this.username, required this.password});
1517

1618
@override
17-
Future<String> handle(Uri authorizationEndpoint, String identifier, String secret) async {
19+
Future<String> handle(
20+
Uri authorizationEndpoint, String identifier, String secret) async {
1821
final client = await oauth.resourceOwnerPasswordGrant(
1922
authorizationEndpoint,
2023
username,
@@ -31,7 +34,8 @@ class ClientCredentialsGrant extends OAuthGrant {
3134
const ClientCredentialsGrant();
3235

3336
@override
34-
Future<String> handle(Uri authorizationEndpoint, String identifier, String secret) async {
37+
Future<String> handle(
38+
Uri authorizationEndpoint, String identifier, String secret) async {
3539
final client = await oauth.clientCredentialsGrant(
3640
authorizationEndpoint,
3741
identifier,

lib/src/oauth_token.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ class OAuthToken {
55
final String? refreshToken;
66
final DateTime? expiration;
77

8-
bool get isExpired => expiration != null && DateTime.now().isAfter(expiration!);
8+
bool get isExpired =>
9+
expiration != null && DateTime.now().isAfter(expiration!);
910

1011
const OAuthToken._(
1112
this.accessToken,

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: oauth_chopper
22
description: Add and manage OAuth2 authentication for your Chopper client.
3-
version: 0.0.1
3+
version: 0.0.2
44
homepage: https://github.com/DutchCodingCompany/oauth_chopper
55

66
environment:

test/oauth_authenticator_test.dart

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@ void main() {
2323
),
2424
);
2525
final testRequest = Request('GET', 'test', 'test');
26-
final unauthorizedResponse = Response(http.Response('body', HttpStatus.unauthorized), 'body');
27-
final authorizedResponse = Response(http.Response('body', HttpStatus.accepted), 'body');
26+
final unauthorizedResponse =
27+
Response(http.Response('body', HttpStatus.unauthorized), 'body');
28+
final authorizedResponse =
29+
Response(http.Response('body', HttpStatus.accepted), 'body');
2830

2931
test('only refresh on unauthorized and token', () async {
3032
// arrange
@@ -34,7 +36,8 @@ void main() {
3436
final expected = {'Authorization': 'Bearer token'};
3537

3638
// act
37-
final result = await authenticator.authenticate(testRequest, unauthorizedResponse);
39+
final result =
40+
await authenticator.authenticate(testRequest, unauthorizedResponse);
3841

3942
// assert
4043
verify(mockOAuthChopper.refresh()).called(1);
@@ -48,7 +51,8 @@ void main() {
4851
final authenticator = OAuthAuthenticator(mockOAuthChopper, null);
4952

5053
// act
51-
final result = await authenticator.authenticate(testRequest, authorizedResponse);
54+
final result =
55+
await authenticator.authenticate(testRequest, authorizedResponse);
5256

5357
// assert
5458
verifyNever(mockOAuthChopper.refresh());
@@ -62,7 +66,8 @@ void main() {
6266
final authenticator = OAuthAuthenticator(mockOAuthChopper, null);
6367

6468
// act
65-
final result = await authenticator.authenticate(testRequest, unauthorizedResponse);
69+
final result =
70+
await authenticator.authenticate(testRequest, unauthorizedResponse);
6671

6772
// assert
6873
verifyNever(mockOAuthChopper.refresh());
@@ -76,7 +81,8 @@ void main() {
7681
final authenticator = OAuthAuthenticator(mockOAuthChopper, null);
7782

7883
// act
79-
final result = await authenticator.authenticate(testRequest, unauthorizedResponse);
84+
final result =
85+
await authenticator.authenticate(testRequest, unauthorizedResponse);
8086

8187
// assert
8288
verify(mockOAuthChopper.refresh()).called(1);
@@ -91,18 +97,23 @@ void main() {
9197

9298
// act
9399
// assert
94-
expect(() async => await authenticator.authenticate(testRequest, unauthorizedResponse), throwsFormatException);
100+
expect(
101+
() async =>
102+
await authenticator.authenticate(testRequest, unauthorizedResponse),
103+
throwsFormatException);
95104
});
96105

97106
test("Exception not thrown if onError is supplied", () async {
98107
// arrange
99108
FormatException? result;
100109
when(mockOAuthChopper.refresh()).thenThrow(FormatException('failed'));
101110
when(mockOAuthChopper.token).thenAnswer((_) async => testToken);
102-
final authenticator = OAuthAuthenticator(mockOAuthChopper, (e, s) => result = e as FormatException);
111+
final authenticator = OAuthAuthenticator(
112+
mockOAuthChopper, (e, s) => result = e as FormatException);
103113

104114
// act
105-
final responseResult = await authenticator.authenticate(testRequest, unauthorizedResponse);
115+
final responseResult =
116+
await authenticator.authenticate(testRequest, unauthorizedResponse);
106117

107118
// assert
108119
expect(result?.message, 'failed');

test/oauth_chopper_test.dart

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@ void main() {
2222

2323
test('oauth_chopper returns interceptor which contains oauth_chopper', () {
2424
// arrange
25-
final oauthChopper =
26-
OAuthChopper(authorizationEndpoint: Uri.parse('endpoint'), identifier: 'identifier', secret: 'secret');
25+
final oauthChopper = OAuthChopper(
26+
authorizationEndpoint: Uri.parse('endpoint'),
27+
identifier: 'identifier',
28+
secret: 'secret');
2729

2830
// act
2931
final inteceptor = oauthChopper.interceptor;
@@ -34,8 +36,10 @@ void main() {
3436

3537
test('oauth_chopper returns authenticator which contains oauth_chopper', () {
3638
// arrange
37-
final oauthChopper =
38-
OAuthChopper(authorizationEndpoint: Uri.parse('endpoint'), identifier: 'identifier', secret: 'secret');
39+
final oauthChopper = OAuthChopper(
40+
authorizationEndpoint: Uri.parse('endpoint'),
41+
identifier: 'identifier',
42+
secret: 'secret');
3943

4044
// act
4145
final authenticator = oauthChopper.authenticator();
@@ -48,7 +52,10 @@ void main() {
4852
// arrange
4953
when(storageMock.fetchCredentials()).thenAnswer((_) => testJson);
5054
final oauthChopper = OAuthChopper(
51-
authorizationEndpoint: Uri.parse('endpoint'), identifier: 'identifier', secret: 'secret', storage: storageMock);
55+
authorizationEndpoint: Uri.parse('endpoint'),
56+
identifier: 'identifier',
57+
secret: 'secret',
58+
storage: storageMock);
5259

5360
// act
5461
final token = await oauthChopper.token;
@@ -62,7 +69,10 @@ void main() {
6269
// arrange
6370
when(storageMock.fetchCredentials()).thenAnswer((_) => null);
6471
final oauthChopper = OAuthChopper(
65-
authorizationEndpoint: Uri.parse('endpoint'), identifier: 'identifier', secret: 'secret', storage: storageMock);
72+
authorizationEndpoint: Uri.parse('endpoint'),
73+
identifier: 'identifier',
74+
secret: 'secret',
75+
storage: storageMock);
6676

6777
// act
6878
final token = await oauthChopper.token;
@@ -76,7 +86,10 @@ void main() {
7686
when(storageMock.saveCredentials(any)).thenAnswer((_) => null);
7787
when(grantMock.handle(any, any, any)).thenAnswer((_) async => testJson);
7888
final oauthChopper = OAuthChopper(
79-
authorizationEndpoint: Uri.parse('endpoint'), identifier: 'identifier', secret: 'secret', storage: storageMock);
89+
authorizationEndpoint: Uri.parse('endpoint'),
90+
identifier: 'identifier',
91+
secret: 'secret',
92+
storage: storageMock);
8093

8194
// act
8295
final token = await oauthChopper.requestGrant(grantMock);
@@ -87,6 +100,4 @@ void main() {
87100
expect(token.accessToken, 'accesToken');
88101
expect(token.refreshToken, 'refreshToken');
89102
});
90-
91-
92103
}

0 commit comments

Comments
 (0)