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.

Inheritance

Constructors

Client(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. [...]
read-only
hashCode int
The hash code for this object. [...]
read-only, inherited
identifier String
The client identifier for this client. [...]
final
runtimeType Type
A representation of the runtime type of the object.
read-only, inherited
secret String
The client secret for this client. [...]
final

Methods

close() → void
Closes this client and its underlying HTTP client.
override
delete(dynamic url, {Map<String, String> headers}) Future<Response>
Sends an HTTP DELETE request with the given headers to the given URL, which can be a Uri or a String. [...]
inherited
get(dynamic url, {Map<String, String> headers}) Future<Response>
Sends an HTTP GET request with the given headers to the given URL, which can be a Uri or a String. [...]
inherited
Sends an HTTP HEAD request with the given headers to the given URL, which can be a Uri or a String. [...]
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed. [...]
inherited
patch(dynamic url, {Map<String, String> headers, dynamic body, Encoding encoding}) Future<Response>
Sends an HTTP PATCH request with the given headers and body to the given URL, which can be a Uri or a String. [...]
inherited
post(dynamic url, {Map<String, String> headers, dynamic body, Encoding encoding}) Future<Response>
Sends an HTTP POST request with the given headers and body to the given URL, which can be a Uri or a String. [...]
inherited
put(dynamic url, {Map<String, String> headers, dynamic body, Encoding encoding}) Future<Response>
Sends an HTTP PUT request with the given headers and body to the given URL, which can be a Uri or a String. [...]
inherited
read(dynamic url, {Map<String, String> headers}) Future<String>
Sends an HTTP GET request with the given headers to the given URL, which can be a Uri or a String, and returns a Future that completes to the body of the response as a String. [...]
inherited
readBytes(dynamic url, {Map<String, String> headers}) Future<Uint8List>
Sends an HTTP GET request with the given headers to the given URL, which can be a Uri or a String, 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. [...]
override
toString() String
Returns a string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator. [...]
inherited