Skip to content
Open
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
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;
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();
}
}
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