diff --git a/CHANGELOG.md b/CHANGELOG.md index 906517d..2c5da18 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 2.0.3-wip + +* Require `package:http` v1.0.0 + ## 2.0.2 * Require Dart 3.0. diff --git a/analysis_options.yaml b/analysis_options.yaml index c8bc59c..68d2a49 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -1,6 +1,9 @@ -include: package:lints/recommended.yaml +include: package:dart_flutter_team_lints/analysis_options.yaml analyzer: + errors: + # Too many exceptions + comment_references: ignore language: strict-casts: true strict-raw-types: true diff --git a/lib/src/credentials.dart b/lib/src/credentials.dart index a11b2ba..088b482 100644 --- a/lib/src/credentials.dart +++ b/lib/src/credentials.dart @@ -24,9 +24,9 @@ typedef CredentialsRefreshedCallback = void Function(Credentials); /// /// Many authorization servers will attach an expiration date to a set of /// credentials, along with a token that can be used to refresh the credentials -/// once they've expired. The [Client] will automatically refresh its +/// once they've expired. The [http.Client] will automatically refresh its /// credentials when necessary. It's also possible to explicitly refresh them -/// via [Client.refreshCredentials] or [Credentials.refresh]. +/// via [http.Client.refreshCredentials] or [Credentials.refresh]. /// /// Note that a given set of credentials can only be refreshed once, so be sure /// to save the refreshed credentials for future use. diff --git a/lib/src/handle_access_token_response.dart b/lib/src/handle_access_token_response.dart index 931ae9d..f318e3b 100644 --- a/lib/src/handle_access_token_response.dart +++ b/lib/src/handle_access_token_response.dart @@ -74,7 +74,9 @@ Credentials handleAccessTokenResponse(http.Response response, Uri tokenEndpoint, expiresIn = double.parse(expiresIn).toInt(); } on FormatException { throw FormatException( - 'parameter "expires_in" could not be parsed as in, was: "$expiresIn"'); + 'parameter "expires_in" could not be parsed as in, was: ' + '"$expiresIn"', + ); } } else if (expiresIn is! int) { throw FormatException( diff --git a/pubspec.yaml b/pubspec.yaml index 544a126..d019335 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,5 +1,5 @@ name: oauth2 -version: 2.0.2 +version: 2.0.3-wip description: >- A client library for authenticating with a remote service via OAuth2 on behalf of a user, and making authorized HTTP requests with the user's @@ -12,9 +12,9 @@ environment: dependencies: collection: ^1.15.0 crypto: ^3.0.0 - http: '>=0.13.0 <2.0.0' + http: ^1.0.0 http_parser: ^4.0.0 dev_dependencies: - lints: ^2.0.0 + dart_flutter_team_lints: ^2.0.0 test: ^1.16.0 diff --git a/test/authorization_code_grant_test.dart b/test/authorization_code_grant_test.dart index b4807bc..06e88af 100644 --- a/test/authorization_code_grant_test.dart +++ b/test/authorization_code_grant_test.dart @@ -177,7 +177,7 @@ void main() { test('with an error parameter throws an AuthorizationException', () { grant.getAuthorizationUrl(redirectUrl); expect(grant.handleAuthorizationResponse({'error': 'invalid_request'}), - throwsA((e) => e is oauth2.AuthorizationException)); + throwsA(isA())); }); test('sends an authorization code request', () { diff --git a/test/client_credentials_grant_test.dart b/test/client_credentials_grant_test.dart index 67c71a5..28de425 100644 --- a/test/client_credentials_grant_test.dart +++ b/test/client_credentials_grant_test.dart @@ -3,6 +3,7 @@ // BSD-style license that can be found in the LICENSE file. @TestOn('vm') +library; import 'dart:convert'; diff --git a/test/client_test.dart b/test/client_test.dart index b583f8c..3c30d36 100644 --- a/test/client_test.dart +++ b/test/client_test.dart @@ -67,45 +67,47 @@ void main() { }); test( - 'that can be refreshed refreshes only once if multiple requests are made', - () async { - var expiration = DateTime.now().subtract(const Duration(hours: 1)); - var credentials = oauth2.Credentials('access token', - refreshToken: 'refresh token', - tokenEndpoint: tokenEndpoint, - expiration: expiration); - var client = oauth2.Client(credentials, - identifier: 'identifier', secret: 'secret', httpClient: httpClient); + 'that can be refreshed refreshes only once if multiple requests are made', + () async { + var expiration = DateTime.now().subtract(const Duration(hours: 1)); + var credentials = oauth2.Credentials('access token', + refreshToken: 'refresh token', + tokenEndpoint: tokenEndpoint, + expiration: expiration); + var client = oauth2.Client(credentials, + identifier: 'identifier', secret: 'secret', httpClient: httpClient); - httpClient.expectRequest((request) { - expect(request.method, equals('POST')); - expect(request.url.toString(), equals(tokenEndpoint.toString())); - return Future.value(http.Response( - jsonEncode( - {'access_token': 'new access token', 'token_type': 'bearer'}), - 200, - headers: {'content-type': 'application/json'})); - }); + httpClient.expectRequest((request) { + expect(request.method, equals('POST')); + expect(request.url.toString(), equals(tokenEndpoint.toString())); + return Future.value(http.Response( + jsonEncode( + {'access_token': 'new access token', 'token_type': 'bearer'}), + 200, + headers: {'content-type': 'application/json'})); + }); - const numCalls = 2; + const numCalls = 2; - for (var i = 0; i < numCalls; i++) { - httpClient.expectRequest((request) { - expect(request.method, equals('GET')); - expect(request.url.toString(), equals(requestUri.toString())); - expect(request.headers['authorization'], - equals('Bearer new access token')); + for (var i = 0; i < numCalls; i++) { + httpClient.expectRequest((request) { + expect(request.method, equals('GET')); + expect(request.url.toString(), equals(requestUri.toString())); + expect(request.headers['authorization'], + equals('Bearer new access token')); - return Future.value(http.Response('good job', 200)); - }); - } + return Future.value(http.Response('good job', 200)); + }); + } - await Future.wait( - List>.generate(numCalls, (_) => client.read(requestUri)), - ); + await Future.wait( + List>.generate( + numCalls, (_) => client.read(requestUri)), + ); - expect(client.credentials.accessToken, equals('new access token')); - }); + expect(client.credentials.accessToken, equals('new access token')); + }, + ); test('that onCredentialsRefreshed is called', () async { var callbackCalled = false; diff --git a/test/handle_access_token_response_test.dart b/test/handle_access_token_response_test.dart index 481c1af..4d7b519 100644 --- a/test/handle_access_token_response_test.dart +++ b/test/handle_access_token_response_test.dart @@ -115,11 +115,11 @@ void main() { group('a success response', () { oauth2.Credentials handleSuccess( {String contentType = 'application/json', - accessToken = 'access token', - tokenType = 'bearer', - expiresIn, - refreshToken, - scope}) { + Object? accessToken = 'access token', + Object? tokenType = 'bearer', + Object? expiresIn, + Object? refreshToken, + Object? scope}) { return handle(http.Response( jsonEncode({ 'access_token': accessToken, @@ -272,11 +272,11 @@ void main() { group('a success response with a id_token', () { oauth2.Credentials handleSuccess( {String contentType = 'application/json', - accessToken = 'access token', - tokenType = 'bearer', - expiresIn, - idToken = 'decode me', - scope}) { + Object? accessToken = 'access token', + Object? tokenType = 'bearer', + Object? expiresIn, + Object? idToken = 'decode me', + Object? scope}) { return handle(http.Response( jsonEncode({ 'access_token': accessToken, diff --git a/test/resource_owner_password_grant_test.dart b/test/resource_owner_password_grant_test.dart index 2614b14..7a5d9b5 100644 --- a/test/resource_owner_password_grant_test.dart +++ b/test/resource_owner_password_grant_test.dart @@ -3,6 +3,8 @@ // BSD-style license that can be found in the LICENSE file. @TestOn('vm') +library; + import 'dart:async'; import 'dart:convert'; diff --git a/test/utils.dart b/test/utils.dart index 90980c8..4f3b747 100644 --- a/test/utils.dart +++ b/test/utils.dart @@ -22,7 +22,7 @@ class ExpectClient extends MockClient { } void expectRequest(MockClientHandler fn) { - var completer = Completer(); + var completer = Completer(); expect(completer.future, completes); _handlers.add((request) {