Thanks to visit codestin.com
Credit goes to github.com

Skip to content
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 pkgs/oauth2/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.0.5

* Make underlying HTTP client non-nullable to inherit its close behavior.

## 2.0.4

* Updated README with example for Flutter Web.
Expand Down
7 changes: 3 additions & 4 deletions pkgs/oauth2/lib/src/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class Client extends http.BaseClient {
final bool _basicAuth;

/// The underlying HTTP client.
http.Client? _httpClient;
final http.Client _httpClient;

/// Creates a new client from a pre-existing set of credentials.
///
Expand Down Expand Up @@ -111,7 +111,7 @@ class Client extends http.BaseClient {
}

request.headers['authorization'] = 'Bearer ${credentials.accessToken}';
var response = await _httpClient!.send(request);
var response = await _httpClient.send(request);

if (response.statusCode != 401) return response;
if (!response.headers.containsKey('www-authenticate')) return response;
Expand Down Expand Up @@ -181,7 +181,6 @@ class Client extends http.BaseClient {
/// Closes this client and its underlying HTTP client.
@override
void close() {
_httpClient?.close();
_httpClient = null;
_httpClient.close();
}
}
2 changes: 1 addition & 1 deletion pkgs/oauth2/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: oauth2
version: 2.0.4
version: 2.0.5
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 Down
18 changes: 18 additions & 0 deletions pkgs/oauth2/test/client_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,24 @@ void main() {

expect(client.refreshCredentials(), throwsA(isStateError));
});

test("won't send a request with closed client", () {
var credentials = oauth2.Credentials('access token');

var client = oauth2.Client(
credentials,
identifier: 'identifier',
secret: 'secret',
httpClient: httpClient,
);

client.close();

expect(
client.read(requestUri),
throwsA(const TypeMatcher<http.ClientException>()),
);
});
});

group('with invalid credentials', () {
Expand Down