Client class
An OAuth2 client.
This acts as a drop-in replacement for an http.Client
, while sending
OAuth2 authorization credentials along with each request.
The client also automatically refreshes its credentials if possible. When it makes a request, if its credentials are expired, it will first refresh them. This means that any request may throw an AuthorizationException if the refresh is not authorized for some reason, a FormatException if the authorization server provides ill-formatted responses, or an ExpirationException if the credentials are expired and can't be refreshed.
The client will also throw an AuthorizationException if the resource server returns a 401 response with a WWW-Authenticate header indicating that the current credentials are invalid.
If you already have a set of Credentials, you can construct a Client directly. However, in order to first obtain the credentials, you must authorize. At the time of writing, the only authorization method this library supports is AuthorizationCodeGrant.
Constructors
- Client.new(Credentials _credentials, {String? identifier, String? secret, CredentialsRefreshedCallback? onCredentialsRefreshed, bool basicAuth = true, Client? httpClient})
- Creates a new client from a pre-existing set of credentials.
Properties
- credentials → Credentials
-
The credentials this client uses to prove to the resource server that it's
authorized.
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- identifier → String?
-
The client identifier for this client.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- secret → String?
-
The client secret for this client.
final
Methods
-
close(
) → void - Closes this client and its underlying HTTP client.
-
delete(
Uri url, {Map< String, String> ? headers, Object? body, Encoding? encoding}) → Future<Response> -
Sends an HTTP DELETE request with the given headers to the given URL.
inherited
-
get(
Uri url, {Map< String, String> ? headers}) → Future<Response> -
Sends an HTTP GET request with the given headers to the given URL.
inherited
-
head(
Uri url, {Map< String, String> ? headers}) → Future<Response> -
Sends an HTTP HEAD request with the given headers to the given URL.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
patch(
Uri url, {Map< String, String> ? headers, Object? body, Encoding? encoding}) → Future<Response> -
Sends an HTTP PATCH request with the given headers and body to the given
URL.
inherited
-
post(
Uri url, {Map< String, String> ? headers, Object? body, Encoding? encoding}) → Future<Response> -
Sends an HTTP POST request with the given headers and body to the given
URL.
inherited
-
put(
Uri url, {Map< String, String> ? headers, Object? body, Encoding? encoding}) → Future<Response> -
Sends an HTTP PUT request with the given headers and body to the given
URL.
inherited
-
read(
Uri url, {Map< String, String> ? headers}) → Future<String> -
Sends an HTTP GET request with the given headers to the given URL and
returns a Future that completes to the body of the response as a String.
inherited
-
readBytes(
Uri url, {Map< String, String> ? headers}) → Future<Uint8List> -
Sends an HTTP GET request with the given headers to the given URL and
returns a Future that completes to the body of the response as a list of
bytes.
inherited
-
refreshCredentials(
[List< String> ? newScopes]) → Future<Client> - Explicitly refreshes this client's credentials. Returns this client.
-
send(
BaseRequest request) → Future< StreamedResponse> - Sends an HTTP request with OAuth2 authorization credentials attached.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited