Skip to content

Commit 70002e9

Browse files
authored
Merge pull request #8 from DutchCodingCompany/feature/update-dependencies
Updated dependencies + small improvements
2 parents 2f422a6 + ece1f27 commit 70002e9

14 files changed

+112
-298
lines changed

.github/workflows/dart.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# This workflow uses actions that are not certified by GitHub.
2+
# They are provided by a third-party and are governed by
3+
# separate terms of service, privacy policy, and support
4+
# documentation.
5+
6+
name: Dart
7+
8+
on:
9+
push:
10+
branches: [ "main" ]
11+
pull_request:
12+
branches: [ "main" ]
13+
14+
jobs:
15+
build:
16+
runs-on: ubuntu-latest
17+
18+
steps:
19+
- uses: actions/checkout@v3
20+
21+
# Note: This workflow uses the latest stable version of the Dart SDK.
22+
# You can specify other versions if desired, see documentation here:
23+
# https://github.com/dart-lang/setup-dart/blob/main/README.md
24+
# - uses: dart-lang/setup-dart@v1
25+
- uses: dart-lang/setup-dart@9a04e6d73cca37bd455e0608d7e5092f881fd603
26+
27+
- name: Install dependencies
28+
run: dart pub get
29+
30+
- name: Check code format
31+
run: dart format . -o none --set-exit-if-changed
32+
33+
# Uncomment this step to verify the use of 'dart format' on each commit.
34+
# - name: Verify formatting
35+
# run: dart format --output=none --set-exit-if-changed .
36+
37+
# Consider passing '--fatal-infos' for slightly stricter analysis.
38+
- name: Analyze project source
39+
run: dart analyze
40+
41+
# Your project will need to have tests in test/ and a dependency on
42+
# package:test for this step to succeed. Note that Flutter projects will
43+
# want to change this to 'flutter test'.
44+
- name: Run tests
45+
run: dart test

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## 0.2.0
2+
3+
- Updated dependencies to latest versions. Including `chopper: 7.0.4` and `http: 1.1.0`.
4+
- Added basic github action checks.
5+
- Removed mockito in favor of mocktail.
6+
17
## 0.1.2
28

39
- Add ID token to OAuth token

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ Example:
4848
4949
/// Add the oauth authenticator and interceptor to the chopper client.
5050
final chopperClient = ChopperClient(
51-
baseUrl: 'https://example.com',
51+
baseUrl: Uri.parse('https://example.com'),
5252
authenticator: oauthChopper.authenticator(),
5353
interceptors: [
5454
oauthChopper.interceptor,

example/oauth_chopper_example.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ void main() {
1717

1818
/// Add the oauth authenticator and interceptor to the chopper client.
1919
final chopperClient = ChopperClient(
20-
baseUrl: Uri(host: 'https://example.com'),
20+
baseUrl: Uri.parse('https://example.com'),
2121
authenticator: oauthChopper.authenticator(),
2222
interceptors: [
2323
oauthChopper.interceptor,

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_interceptor.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import 'package:oauth_chopper/src/extensions/request.dart';
77
/// OAuthInterceptor is responsible for adding 'Authorization' header to requests.
88
/// The header is only added if there is a token available. When no token is available no header is added.
99
/// Its added as a Bearer token.
10-
class OAuthInterceptor extends RequestInterceptor {
10+
class OAuthInterceptor implements RequestInterceptor {
1111
OAuthInterceptor(this.oauthChopper);
1212

1313
final OAuthChopper oauthChopper;

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,

pubspec.yaml

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
name: oauth_chopper
22
description: Add and manage OAuth2 authentication for your Chopper client.
3-
version: 0.1.2
3+
version: 0.2.0
44
homepage: https://github.com/DutchCodingCompany/oauth_chopper
55

66
environment:
77
sdk: '>=3.0.0 <4.0.0'
88

99
dependencies:
10-
chopper: ^6.1.3
11-
oauth2: ^2.0.0
10+
chopper: ^7.0.4
11+
oauth2: ^2.0.2
1212

1313
dev_dependencies:
14-
build_runner: ^2.2.1
15-
lints: ^2.0.0
16-
test: ^1.21.6
17-
mockito: ^5.3.0
18-
http: ^0.13.5
14+
http: ^1.1.0
15+
lints: ^2.1.1
16+
mocktail: ^1.0.0
17+
test: ^1.24.6

test/oauth_authenticator_test.dart

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,14 @@ import 'dart:io';
22

33
import 'package:chopper/chopper.dart';
44
import 'package:http/http.dart' as http;
5-
import 'package:mockito/annotations.dart';
6-
import 'package:mockito/mockito.dart';
5+
import 'package:mocktail/mocktail.dart';
76
import 'package:oauth2/oauth2.dart';
87
import 'package:oauth_chopper/src/oauth_authenticator.dart';
98
import 'package:oauth_chopper/src/oauth_chopper.dart';
109
import 'package:oauth_chopper/src/oauth_token.dart';
1110
import 'package:test/test.dart';
1211

13-
@GenerateMocks([OAuthChopper])
14-
import 'oauth_authenticator_test.mocks.dart';
12+
class MockOAuthChopper extends Mock implements OAuthChopper {}
1513

1614
void main() {
1715
final mockOAuthChopper = MockOAuthChopper();
@@ -22,16 +20,16 @@ void main() {
2220
expiration: DateTime(2022, 9, 1),
2321
),
2422
);
25-
final testRequest = Request('GET', Uri(host: 'test'), Uri(host: 'test'));
23+
final testRequest = Request('GET', Uri.parse('test'), Uri.parse('test'));
2624
final unauthorizedResponse =
2725
Response(http.Response('body', HttpStatus.unauthorized), 'body');
2826
final authorizedResponse =
2927
Response(http.Response('body', HttpStatus.accepted), 'body');
3028

3129
test('only refresh on unauthorized and token', () async {
3230
// arrange
33-
when(mockOAuthChopper.refresh()).thenAnswer((_) async => testToken);
34-
when(mockOAuthChopper.token).thenAnswer((_) async => testToken);
31+
when(() => mockOAuthChopper.refresh()).thenAnswer((_) async => testToken);
32+
when(() => mockOAuthChopper.token).thenAnswer((_) async => testToken);
3533
final authenticator = OAuthAuthenticator(mockOAuthChopper, null);
3634
final expected = {'Authorization': 'Bearer token'};
3735

@@ -40,59 +38,59 @@ void main() {
4038
await authenticator.authenticate(testRequest, unauthorizedResponse);
4139

4240
// assert
43-
verify(mockOAuthChopper.refresh()).called(1);
41+
verify(() => mockOAuthChopper.refresh()).called(1);
4442
expect(result?.headers, expected);
4543
});
4644

4745
test("Don't refresh on authorized", () async {
4846
// arrange
49-
when(mockOAuthChopper.refresh()).thenAnswer((_) async => testToken);
50-
when(mockOAuthChopper.token).thenAnswer((_) async => testToken);
47+
when(() => mockOAuthChopper.refresh()).thenAnswer((_) async => testToken);
48+
when(() => mockOAuthChopper.token).thenAnswer((_) async => testToken);
5149
final authenticator = OAuthAuthenticator(mockOAuthChopper, null);
5250

5351
// act
5452
final result =
5553
await authenticator.authenticate(testRequest, authorizedResponse);
5654

5755
// assert
58-
verifyNever(mockOAuthChopper.refresh());
56+
verifyNever(() => mockOAuthChopper.refresh());
5957
expect(result, null);
6058
});
6159

6260
test("Don't refresh on token not available", () async {
6361
// arrange
64-
when(mockOAuthChopper.refresh()).thenAnswer((_) async => testToken);
65-
when(mockOAuthChopper.token).thenAnswer((_) async => null);
62+
when(() => mockOAuthChopper.refresh()).thenAnswer((_) async => testToken);
63+
when(() => mockOAuthChopper.token).thenAnswer((_) async => null);
6664
final authenticator = OAuthAuthenticator(mockOAuthChopper, null);
6765

6866
// act
6967
final result =
7068
await authenticator.authenticate(testRequest, unauthorizedResponse);
7169

7270
// assert
73-
verifyNever(mockOAuthChopper.refresh());
71+
verifyNever(() => mockOAuthChopper.refresh());
7472
expect(result, null);
7573
});
7674

7775
test("Don't add headers on failed refresh", () async {
7876
// arrange
79-
when(mockOAuthChopper.refresh()).thenAnswer((_) async => null);
80-
when(mockOAuthChopper.token).thenAnswer((_) async => testToken);
77+
when(() => mockOAuthChopper.refresh()).thenAnswer((_) async => null);
78+
when(() => mockOAuthChopper.token).thenAnswer((_) async => testToken);
8179
final authenticator = OAuthAuthenticator(mockOAuthChopper, null);
8280

8381
// act
8482
final result =
8583
await authenticator.authenticate(testRequest, unauthorizedResponse);
8684

8785
// assert
88-
verify(mockOAuthChopper.refresh()).called(1);
86+
verify(() => mockOAuthChopper.refresh()).called(1);
8987
expect(result, null);
9088
});
9189

9290
test("Exception thrown if onError is null", () async {
9391
// arrange
94-
when(mockOAuthChopper.refresh()).thenThrow(FormatException('failed'));
95-
when(mockOAuthChopper.token).thenAnswer((_) async => testToken);
92+
when(() => mockOAuthChopper.refresh()).thenThrow(FormatException('failed'));
93+
when(() => mockOAuthChopper.token).thenAnswer((_) async => testToken);
9694
final authenticator = OAuthAuthenticator(mockOAuthChopper, null);
9795

9896
// act
@@ -106,8 +104,8 @@ void main() {
106104
test("Exception not thrown if onError is supplied", () async {
107105
// arrange
108106
FormatException? result;
109-
when(mockOAuthChopper.refresh()).thenThrow(FormatException('failed'));
110-
when(mockOAuthChopper.token).thenAnswer((_) async => testToken);
107+
when(() => mockOAuthChopper.refresh()).thenThrow(FormatException('failed'));
108+
when(() => mockOAuthChopper.token).thenAnswer((_) async => testToken);
111109
final authenticator = OAuthAuthenticator(
112110
mockOAuthChopper, (e, s) => result = e as FormatException);
113111

test/oauth_authenticator_test.mocks.dart

Lines changed: 0 additions & 98 deletions
This file was deleted.

0 commit comments

Comments
 (0)