Skip to content
This repository has been archived by the owner on Aug 26, 2024. It is now read-only.

Move to latest lints, fixes, bump pkg:http dep #162

Merged
merged 1 commit into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.0.3-wip

* Require `package:http` v1.0.0

## 2.0.2

* Require Dart 3.0.
Expand Down
5 changes: 4 additions & 1 deletion analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/src/credentials.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 3 additions & 1 deletion lib/src/handle_access_token_response.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
6 changes: 3 additions & 3 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
2 changes: 1 addition & 1 deletion test/authorization_code_grant_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<oauth2.AuthorizationException>()));
});

test('sends an authorization code request', () {
Expand Down
1 change: 1 addition & 0 deletions test/client_credentials_grant_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// BSD-style license that can be found in the LICENSE file.

@TestOn('vm')
library;

import 'dart:convert';

Expand Down
68 changes: 35 additions & 33 deletions test/client_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<Future<String>>.generate(numCalls, (_) => client.read(requestUri)),
);
await Future.wait(
List<Future<String>>.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;
Expand Down
20 changes: 10 additions & 10 deletions test/handle_access_token_response_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions test/resource_owner_password_grant_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
// BSD-style license that can be found in the LICENSE file.

@TestOn('vm')
library;

import 'dart:async';
import 'dart:convert';

Expand Down
2 changes: 1 addition & 1 deletion test/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class ExpectClient extends MockClient {
}

void expectRequest(MockClientHandler fn) {
var completer = Completer();
var completer = Completer<void>();
expect(completer.future, completes);

_handlers.add((request) {
Expand Down