Skip to content

Commit ece1f27

Browse files
committed
🎨 Formatted files
1 parent 8f456dc commit ece1f27

File tree

5 files changed

+57
-26
lines changed

5 files changed

+57
-26
lines changed

lib/src/oauth_chopper.dart

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ class OAuthChopper {
5151
/// Get stored [OAuthToken].
5252
Future<OAuthToken?> get token async {
5353
final credentialsJson = await _storage.fetchCredentials();
54-
return credentialsJson != null ? OAuthToken.fromJson(credentialsJson) : null;
54+
return credentialsJson != null
55+
? OAuthToken.fromJson(credentialsJson)
56+
: null;
5557
}
5658

5759
/// Provides an [OAuthAuthenticator] instance.
@@ -72,7 +74,8 @@ class OAuthChopper {
7274
if (credentialsJson == null) return null;
7375
final credentials = Credentials.fromJson(credentialsJson);
7476
try {
75-
final newCredentials = await credentials.refresh(identifier: identifier, secret: secret);
77+
final newCredentials =
78+
await credentials.refresh(identifier: identifier, secret: secret);
7679
await _storage.saveCredentials(newCredentials.toJson());
7780
return OAuthToken.fromCredentials(newCredentials);
7881
} catch (e) {
@@ -88,7 +91,8 @@ class OAuthChopper {
8891
///
8992
/// Throws an exception if the grant fails.
9093
Future<OAuthToken> requestGrant(OAuthGrant grant) async {
91-
final credentials = await grant.handle(authorizationEndpoint, identifier, secret);
94+
final credentials =
95+
await grant.handle(authorizationEndpoint, identifier, secret);
9296

9397
await _storage.saveCredentials(credentials);
9498

lib/src/oauth_token.dart

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

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

1112
const OAuthToken._(
1213
this.accessToken,

test/oauth_authenticator_test.dart

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@ void main() {
2121
),
2222
);
2323
final testRequest = Request('GET', Uri.parse('test'), Uri.parse('test'));
24-
final unauthorizedResponse = Response(http.Response('body', HttpStatus.unauthorized), 'body');
25-
final authorizedResponse = Response(http.Response('body', HttpStatus.accepted), 'body');
24+
final unauthorizedResponse =
25+
Response(http.Response('body', HttpStatus.unauthorized), 'body');
26+
final authorizedResponse =
27+
Response(http.Response('body', HttpStatus.accepted), 'body');
2628

2729
test('only refresh on unauthorized and token', () async {
2830
// arrange
@@ -32,7 +34,8 @@ void main() {
3234
final expected = {'Authorization': 'Bearer token'};
3335

3436
// act
35-
final result = await authenticator.authenticate(testRequest, unauthorizedResponse);
37+
final result =
38+
await authenticator.authenticate(testRequest, unauthorizedResponse);
3639

3740
// assert
3841
verify(() => mockOAuthChopper.refresh()).called(1);
@@ -46,7 +49,8 @@ void main() {
4649
final authenticator = OAuthAuthenticator(mockOAuthChopper, null);
4750

4851
// act
49-
final result = await authenticator.authenticate(testRequest, authorizedResponse);
52+
final result =
53+
await authenticator.authenticate(testRequest, authorizedResponse);
5054

5155
// assert
5256
verifyNever(() => mockOAuthChopper.refresh());
@@ -60,7 +64,8 @@ void main() {
6064
final authenticator = OAuthAuthenticator(mockOAuthChopper, null);
6165

6266
// act
63-
final result = await authenticator.authenticate(testRequest, unauthorizedResponse);
67+
final result =
68+
await authenticator.authenticate(testRequest, unauthorizedResponse);
6469

6570
// assert
6671
verifyNever(() => mockOAuthChopper.refresh());
@@ -74,7 +79,8 @@ void main() {
7479
final authenticator = OAuthAuthenticator(mockOAuthChopper, null);
7580

7681
// act
77-
final result = await authenticator.authenticate(testRequest, unauthorizedResponse);
82+
final result =
83+
await authenticator.authenticate(testRequest, unauthorizedResponse);
7884

7985
// assert
8086
verify(() => mockOAuthChopper.refresh()).called(1);
@@ -89,18 +95,23 @@ void main() {
8995

9096
// act
9197
// assert
92-
expect(() async => await authenticator.authenticate(testRequest, unauthorizedResponse), throwsFormatException);
98+
expect(
99+
() async =>
100+
await authenticator.authenticate(testRequest, unauthorizedResponse),
101+
throwsFormatException);
93102
});
94103

95104
test("Exception not thrown if onError is supplied", () async {
96105
// arrange
97106
FormatException? result;
98107
when(() => mockOAuthChopper.refresh()).thenThrow(FormatException('failed'));
99108
when(() => mockOAuthChopper.token).thenAnswer((_) async => testToken);
100-
final authenticator = OAuthAuthenticator(mockOAuthChopper, (e, s) => result = e as FormatException);
109+
final authenticator = OAuthAuthenticator(
110+
mockOAuthChopper, (e, s) => result = e as FormatException);
101111

102112
// act
103-
final responseResult = await authenticator.authenticate(testRequest, unauthorizedResponse);
113+
final responseResult =
114+
await authenticator.authenticate(testRequest, unauthorizedResponse);
104115

105116
// assert
106117
expect(result?.message, 'failed');

test/oauth_chopper_test.dart

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@ void main() {
2626

2727
test('oauth_chopper returns interceptor which contains oauth_chopper', () {
2828
// arrange
29-
final oauthChopper =
30-
OAuthChopper(authorizationEndpoint: Uri.parse('endpoint'), identifier: 'identifier', secret: 'secret');
29+
final oauthChopper = OAuthChopper(
30+
authorizationEndpoint: Uri.parse('endpoint'),
31+
identifier: 'identifier',
32+
secret: 'secret');
3133

3234
// act
3335
final inteceptor = oauthChopper.interceptor;
@@ -38,8 +40,10 @@ void main() {
3840

3941
test('oauth_chopper returns authenticator which contains oauth_chopper', () {
4042
// arrange
41-
final oauthChopper =
42-
OAuthChopper(authorizationEndpoint: Uri.parse('endpoint'), identifier: 'identifier', secret: 'secret');
43+
final oauthChopper = OAuthChopper(
44+
authorizationEndpoint: Uri.parse('endpoint'),
45+
identifier: 'identifier',
46+
secret: 'secret');
4347

4448
// act
4549
final authenticator = oauthChopper.authenticator();
@@ -52,7 +56,10 @@ void main() {
5256
// arrange
5357
when(() => storageMock.fetchCredentials()).thenAnswer((_) => testJson);
5458
final oauthChopper = OAuthChopper(
55-
authorizationEndpoint: Uri.parse('endpoint'), identifier: 'identifier', secret: 'secret', storage: storageMock);
59+
authorizationEndpoint: Uri.parse('endpoint'),
60+
identifier: 'identifier',
61+
secret: 'secret',
62+
storage: storageMock);
5663

5764
// act
5865
final token = await oauthChopper.token;
@@ -67,7 +74,10 @@ void main() {
6774
// arrange
6875
when(() => storageMock.fetchCredentials()).thenAnswer((_) => null);
6976
final oauthChopper = OAuthChopper(
70-
authorizationEndpoint: Uri.parse('endpoint'), identifier: 'identifier', secret: 'secret', storage: storageMock);
77+
authorizationEndpoint: Uri.parse('endpoint'),
78+
identifier: 'identifier',
79+
secret: 'secret',
80+
storage: storageMock);
7181

7282
// act
7383
final token = await oauthChopper.token;
@@ -79,9 +89,13 @@ void main() {
7989
test("Successful grant is stored", () async {
8090
// arrange
8191
when(() => storageMock.saveCredentials(any())).thenAnswer((_) => null);
82-
when(() => grantMock.handle(any(), any(), any())).thenAnswer((_) async => testJson);
92+
when(() => grantMock.handle(any(), any(), any()))
93+
.thenAnswer((_) async => testJson);
8394
final oauthChopper = OAuthChopper(
84-
authorizationEndpoint: Uri.parse('endpoint'), identifier: 'identifier', secret: 'secret', storage: storageMock);
95+
authorizationEndpoint: Uri.parse('endpoint'),
96+
identifier: 'identifier',
97+
secret: 'secret',
98+
storage: storageMock);
8599

86100
// act
87101
final token = await oauthChopper.requestGrant(grantMock);
@@ -90,7 +104,7 @@ void main() {
90104
verify(() => grantMock.handle(any(), 'identifier', 'secret')).called(1);
91105
verify(() => storageMock.saveCredentials(testJson)).called(1);
92106
expect(token.accessToken, 'accesToken');
93-
expect(token?.idToken, 'idToken');
107+
expect(token.idToken, 'idToken');
94108
expect(token.refreshToken, 'refreshToken');
95109
});
96110
}

test/oauth_interceptor_test.dart

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ void main() {
3030

3131
test('HeaderInterceptor adds available token to headers', () async {
3232
// arrange
33-
when(()=>mockOAuthChopper.token).thenAnswer((_) async => testToken);
33+
when(() => mockOAuthChopper.token).thenAnswer((_) async => testToken);
3434
final interceptor = OAuthInterceptor(mockOAuthChopper);
3535
final expected = {'Authorization': 'Bearer token'};
3636

@@ -41,9 +41,10 @@ void main() {
4141
expect(result.headers, expected);
4242
});
4343

44-
test('HeaderInterceptor does not add IDToken when available to headers', () async {
44+
test('HeaderInterceptor does not add IDToken when available to headers',
45+
() async {
4546
// arrange
46-
when(()=>mockOAuthChopper.token).thenAnswer((_) async => testIDtoken);
47+
when(() => mockOAuthChopper.token).thenAnswer((_) async => testIDtoken);
4748
final interceptor = OAuthInterceptor(mockOAuthChopper);
4849
final expected = {'Authorization': 'Bearer token'};
4950

@@ -56,7 +57,7 @@ void main() {
5657

5758
test('HeaderInterceptor adds no token to headers', () async {
5859
// arrange
59-
when(()=>mockOAuthChopper.token).thenAnswer((_) async => null);
60+
when(() => mockOAuthChopper.token).thenAnswer((_) async => null);
6061
final interceptor = OAuthInterceptor(mockOAuthChopper);
6162
final expected = {};
6263

0 commit comments

Comments
 (0)