dart analysis issues fixes (#71)
* dart analysis issues fixes
* fixed formatting
diff --git a/lib/src/authorization_code_grant.dart b/lib/src/authorization_code_grant.dart
index 1e930e1..c04bc0b 100644
--- a/lib/src/authorization_code_grant.dart
+++ b/lib/src/authorization_code_grant.dart
@@ -78,13 +78,13 @@
/// Callback to be invoked whenever the credentials are refreshed.
///
/// This will be passed as-is to the constructed [Client].
- CredentialsRefreshedCallback _onCredentialsRefreshed;
+ final CredentialsRefreshedCallback _onCredentialsRefreshed;
/// Whether to use HTTP Basic authentication for authorizing the client.
final bool _basicAuth;
/// A [String] used to separate scopes; defaults to `" "`.
- String _delimiter;
+ final String _delimiter;
/// The HTTP client used to make HTTP requests.
http.Client _httpClient;
@@ -105,7 +105,7 @@
/// Allowed characters for generating the _codeVerifier
static const String _charset =
- "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~";
+ 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~';
/// The generated PKCE code verifier
String _codeVerifier;
@@ -146,9 +146,10 @@
bool basicAuth = true,
http.Client httpClient,
CredentialsRefreshedCallback onCredentialsRefreshed,
- Map<String, dynamic> getParameters(MediaType contentType, String body)})
+ Map<String, dynamic> Function(MediaType contentType, String body)
+ getParameters})
: _basicAuth = basicAuth,
- _httpClient = httpClient == null ? new http.Client() : httpClient,
+ _httpClient = httpClient ?? http.Client(),
_delimiter = delimiter ?? ' ',
_getParameters = getParameters ?? parseJsonParameters,
_onCredentialsRefreshed = onCredentialsRefreshed;
@@ -175,7 +176,7 @@
Uri getAuthorizationUrl(Uri redirect,
{Iterable<String> scopes, String state}) {
if (_state != _State.initial) {
- throw new StateError('The authorization URL has already been generated.');
+ throw StateError('The authorization URL has already been generated.');
}
_state = _State.awaitingResponse;
@@ -188,23 +189,23 @@
_codeVerifier = _createCodeVerifier();
var codeChallenge = base64Url
.encode(sha256.convert(ascii.encode(_codeVerifier)).bytes)
- .replaceAll("=", "");
+ .replaceAll('=', '');
- this._redirectEndpoint = redirect;
- this._scopes = scopes;
- this._stateString = state;
+ _redirectEndpoint = redirect;
+ _scopes = scopes;
+ _stateString = state;
var parameters = {
- "response_type": "code",
- "client_id": this.identifier,
- "redirect_uri": redirect.toString(),
- "code_challenge": codeChallenge,
- "code_challenge_method": "S256"
+ 'response_type': 'code',
+ 'client_id': identifier,
+ 'redirect_uri': redirect.toString(),
+ 'code_challenge': codeChallenge,
+ 'code_challenge_method': 'S256'
};
if (state != null) parameters['state'] = state;
if (scopes.isNotEmpty) parameters['scope'] = scopes.join(_delimiter);
- return addQueryParameters(this.authorizationEndpoint, parameters);
+ return addQueryParameters(authorizationEndpoint, parameters);
}
/// Processes the query parameters added to a redirect from the authorization
@@ -227,19 +228,19 @@
Future<Client> handleAuthorizationResponse(
Map<String, String> parameters) async {
if (_state == _State.initial) {
- throw new StateError('The authorization URL has not yet been generated.');
+ throw StateError('The authorization URL has not yet been generated.');
} else if (_state == _State.finished) {
- throw new StateError('The authorization code has already been received.');
+ throw StateError('The authorization code has already been received.');
}
_state = _State.finished;
if (_stateString != null) {
if (!parameters.containsKey('state')) {
- throw new FormatException('Invalid OAuth response for '
+ throw FormatException('Invalid OAuth response for '
'"$authorizationEndpoint": parameter "state" expected to be '
'"$_stateString", was missing.');
} else if (parameters['state'] != _stateString) {
- throw new FormatException('Invalid OAuth response for '
+ throw FormatException('Invalid OAuth response for '
'"$authorizationEndpoint": parameter "state" expected to be '
'"$_stateString", was "${parameters['state']}".');
}
@@ -249,9 +250,9 @@
var description = parameters['error_description'];
var uriString = parameters['error_uri'];
var uri = uriString == null ? null : Uri.parse(uriString);
- throw new AuthorizationException(parameters['error'], description, uri);
+ throw AuthorizationException(parameters['error'], description, uri);
} else if (!parameters.containsKey('code')) {
- throw new FormatException('Invalid OAuth response for '
+ throw FormatException('Invalid OAuth response for '
'"$authorizationEndpoint": did not contain required parameter '
'"code".');
}
@@ -276,9 +277,9 @@
/// Throws [AuthorizationException] if the authorization fails.
Future<Client> handleAuthorizationCode(String authorizationCode) async {
if (_state == _State.initial) {
- throw new StateError('The authorization URL has not yet been generated.');
+ throw StateError('The authorization URL has not yet been generated.');
} else if (_state == _State.finished) {
- throw new StateError('The authorization code has already been received.');
+ throw StateError('The authorization code has already been received.');
}
_state = _State.finished;
@@ -288,35 +289,35 @@
/// This works just like [handleAuthorizationCode], except it doesn't validate
/// the state beforehand.
Future<Client> _handleAuthorizationCode(String authorizationCode) async {
- var startTime = new DateTime.now();
+ var startTime = DateTime.now();
var headers = <String, String>{};
var body = {
- "grant_type": "authorization_code",
- "code": authorizationCode,
- "redirect_uri": this._redirectEndpoint.toString(),
- "code_verifier": _codeVerifier
+ 'grant_type': 'authorization_code',
+ 'code': authorizationCode,
+ 'redirect_uri': _redirectEndpoint.toString(),
+ 'code_verifier': _codeVerifier
};
if (_basicAuth && secret != null) {
- headers["Authorization"] = basicAuthHeader(identifier, secret);
+ headers['Authorization'] = basicAuthHeader(identifier, secret);
} else {
// The ID is required for this request any time basic auth isn't being
// used, even if there's no actual client authentication to be done.
- body["client_id"] = identifier;
- if (secret != null) body["client_secret"] = secret;
+ body['client_id'] = identifier;
+ if (secret != null) body['client_secret'] = secret;
}
- var response = await _httpClient.post(this.tokenEndpoint,
- headers: headers, body: body);
+ var response =
+ await _httpClient.post(tokenEndpoint, headers: headers, body: body);
var credentials = handleAccessTokenResponse(
response, tokenEndpoint, startTime, _scopes, _delimiter,
getParameters: _getParameters);
- return new Client(credentials,
- identifier: this.identifier,
- secret: this.secret,
+ return Client(credentials,
+ identifier: identifier,
+ secret: secret,
basicAuth: _basicAuth,
httpClient: _httpClient,
onCredentialsRefreshed: _onCredentialsRefreshed);
@@ -343,21 +344,22 @@
class _State {
/// [AuthorizationCodeGrant.getAuthorizationUrl] has not yet been called for
/// this grant.
- static const initial = const _State("initial");
+ static const initial = _State('initial');
// [AuthorizationCodeGrant.getAuthorizationUrl] has been called but neither
// [AuthorizationCodeGrant.handleAuthorizationResponse] nor
// [AuthorizationCodeGrant.handleAuthorizationCode] has been called.
- static const awaitingResponse = const _State("awaiting response");
+ static const awaitingResponse = _State('awaiting response');
// [AuthorizationCodeGrant.getAuthorizationUrl] and either
// [AuthorizationCodeGrant.handleAuthorizationResponse] or
// [AuthorizationCodeGrant.handleAuthorizationCode] have been called.
- static const finished = const _State("finished");
+ static const finished = _State('finished');
final String _name;
const _State(this._name);
+ @override
String toString() => _name;
}
diff --git a/lib/src/authorization_exception.dart b/lib/src/authorization_exception.dart
index 9ce4b8c..a1b6dd9 100644
--- a/lib/src/authorization_exception.dart
+++ b/lib/src/authorization_exception.dart
@@ -26,6 +26,7 @@
AuthorizationException(this.error, this.description, this.uri);
/// Provides a string description of the AuthorizationException.
+ @override
String toString() {
var header = 'OAuth authorization error ($error)';
if (description != null) {
diff --git a/lib/src/client.dart b/lib/src/client.dart
index 4fa64a1..d33aaa0 100644
--- a/lib/src/client.dart
+++ b/lib/src/client.dart
@@ -92,9 +92,9 @@
http.Client httpClient})
: _basicAuth = basicAuth,
_onCredentialsRefreshed = onCredentialsRefreshed,
- _httpClient = httpClient == null ? new http.Client() : httpClient {
+ _httpClient = httpClient ?? http.Client() {
if (identifier == null && secret != null) {
- throw new ArgumentError("secret may not be passed without identifier.");
+ throw ArgumentError('secret may not be passed without identifier.');
}
}
@@ -102,13 +102,14 @@
///
/// This will also automatically refresh this client's [Credentials] before
/// sending the request if necessary.
+ @override
Future<http.StreamedResponse> send(http.BaseRequest request) async {
if (credentials.isExpired) {
- if (!credentials.canRefresh) throw new ExpirationException(credentials);
+ if (!credentials.canRefresh) throw ExpirationException(credentials);
await refreshCredentials();
}
- request.headers['authorization'] = "Bearer ${credentials.accessToken}";
+ request.headers['authorization'] = 'Bearer ${credentials.accessToken}';
var response = await _httpClient.send(request);
if (response.statusCode != 401) return response;
@@ -130,9 +131,7 @@
var params = challenge.parameters;
if (!params.containsKey('error')) return response;
- throw new AuthorizationException(
- params['error'],
- params['error_description'],
+ throw AuthorizationException(params['error'], params['error_description'],
params['error_uri'] == null ? null : Uri.parse(params['error_uri']));
}
@@ -147,9 +146,9 @@
/// [Credentials.scopes] field of [Client.credentials].
Future<Client> refreshCredentials([List<String> newScopes]) async {
if (!credentials.canRefresh) {
- var prefix = "OAuth credentials";
- if (credentials.isExpired) prefix = "$prefix have expired and";
- throw new StateError("$prefix can't be refreshed.");
+ var prefix = 'OAuth credentials';
+ if (credentials.isExpired) prefix = '$prefix have expired and';
+ throw StateError("$prefix can't be refreshed.");
}
_credentials = await credentials.refresh(
@@ -165,6 +164,7 @@
}
/// Closes this client and its underlying HTTP client.
+ @override
void close() {
if (_httpClient != null) _httpClient.close();
_httpClient = null;
diff --git a/lib/src/client_credentials_grant.dart b/lib/src/client_credentials_grant.dart
index 3c46935..c6d34b9 100644
--- a/lib/src/client_credentials_grant.dart
+++ b/lib/src/client_credentials_grant.dart
@@ -45,12 +45,12 @@
bool basicAuth = true,
http.Client httpClient,
String delimiter,
- Map<String, dynamic> getParameters(
- MediaType contentType, String body)}) async {
+ Map<String, dynamic> Function(MediaType contentType, String body)
+ getParameters}) async {
delimiter ??= ' ';
- var startTime = new DateTime.now();
+ var startTime = DateTime.now();
- var body = {"grant_type": "client_credentials"};
+ var body = {'grant_type': 'client_credentials'};
var headers = <String, String>{};
@@ -63,16 +63,17 @@
}
}
- if (scopes != null && scopes.isNotEmpty)
+ if (scopes != null && scopes.isNotEmpty) {
body['scope'] = scopes.join(delimiter);
+ }
- if (httpClient == null) httpClient = new http.Client();
+ httpClient ??= http.Client();
var response = await httpClient.post(authorizationEndpoint,
headers: headers, body: body);
var credentials = await handleAccessTokenResponse(
response, authorizationEndpoint, startTime, scopes, delimiter,
getParameters: getParameters);
- return new Client(credentials,
+ return Client(credentials,
identifier: identifier, secret: secret, httpClient: httpClient);
}
diff --git a/lib/src/credentials.dart b/lib/src/credentials.dart
index 6ea254d..2b40b05 100644
--- a/lib/src/credentials.dart
+++ b/lib/src/credentials.dart
@@ -81,7 +81,7 @@
/// called. However, since the client's expiration date is kept a few seconds
/// earlier than the server's, there should be enough leeway to rely on this.
bool get isExpired =>
- expiration != null && new DateTime.now().isAfter(expiration);
+ expiration != null && DateTime.now().isAfter(expiration);
/// Whether it's possible to refresh these credentials.
bool get canRefresh => refreshToken != null && tokenEndpoint != null;
@@ -113,8 +113,9 @@
Iterable<String> scopes,
this.expiration,
String delimiter,
- Map<String, dynamic> getParameters(MediaType mediaType, String body)})
- : scopes = new UnmodifiableListView(
+ Map<String, dynamic> Function(MediaType mediaType, String body)
+ getParameters})
+ : scopes = UnmodifiableListView(
// Explicitly type-annotate the list literal to work around
// sdk#24202.
scopes == null ? <String>[] : scopes.toList()),
@@ -125,10 +126,9 @@
///
/// Throws a [FormatException] if the JSON is incorrectly formatted.
factory Credentials.fromJson(String json) {
- validate(condition, message) {
+ void validate(condition, message) {
if (condition) return;
- throw new FormatException(
- "Failed to load credentials: $message.\n\n$json");
+ throw FormatException('Failed to load credentials: $message.\n\n$json');
}
var parsed;
@@ -164,10 +164,10 @@
if (expiration != null) {
validate(expiration is int,
'field "expiration" was not an int, was "$expiration"');
- expiration = new DateTime.fromMillisecondsSinceEpoch(expiration);
+ expiration = DateTime.fromMillisecondsSinceEpoch(expiration);
}
- return new Credentials(parsed['accessToken'],
+ return Credentials(parsed['accessToken'],
refreshToken: parsed['refreshToken'],
idToken: parsed['idToken'],
tokenEndpoint: tokenEndpoint,
@@ -210,32 +210,32 @@
http.Client httpClient}) async {
var scopes = this.scopes;
if (newScopes != null) scopes = newScopes.toList();
- if (scopes == null) scopes = [];
- if (httpClient == null) httpClient = new http.Client();
+ scopes ??= [];
+ httpClient ??= http.Client();
if (identifier == null && secret != null) {
- throw new ArgumentError("secret may not be passed without identifier.");
+ throw ArgumentError('secret may not be passed without identifier.');
}
- var startTime = new DateTime.now();
+ var startTime = DateTime.now();
if (refreshToken == null) {
- throw new StateError("Can't refresh credentials without a refresh "
- "token.");
+ throw StateError("Can't refresh credentials without a refresh "
+ 'token.');
} else if (tokenEndpoint == null) {
- throw new StateError("Can't refresh credentials without a token "
- "endpoint.");
+ throw StateError("Can't refresh credentials without a token "
+ 'endpoint.');
}
var headers = <String, String>{};
- var body = {"grant_type": "refresh_token", "refresh_token": refreshToken};
- if (scopes.isNotEmpty) body["scope"] = scopes.join(_delimiter);
+ var body = {'grant_type': 'refresh_token', 'refresh_token': refreshToken};
+ if (scopes.isNotEmpty) body['scope'] = scopes.join(_delimiter);
if (basicAuth && secret != null) {
- headers["Authorization"] = basicAuthHeader(identifier, secret);
+ headers['Authorization'] = basicAuthHeader(identifier, secret);
} else {
- if (identifier != null) body["client_id"] = identifier;
- if (secret != null) body["client_secret"] = secret;
+ if (identifier != null) body['client_id'] = identifier;
+ if (secret != null) body['client_secret'] = secret;
}
var response =
@@ -247,8 +247,8 @@
// The authorization server may issue a new refresh token. If it doesn't,
// we should re-use the one we already have.
if (credentials.refreshToken != null) return credentials;
- return new Credentials(credentials.accessToken,
- refreshToken: this.refreshToken,
+ return Credentials(credentials.accessToken,
+ refreshToken: refreshToken,
idToken: credentials.idToken,
tokenEndpoint: credentials.tokenEndpoint,
scopes: credentials.scopes,
diff --git a/lib/src/expiration_exception.dart b/lib/src/expiration_exception.dart
index 2df2f8d..d72fcf6 100644
--- a/lib/src/expiration_exception.dart
+++ b/lib/src/expiration_exception.dart
@@ -13,6 +13,7 @@
ExpirationException(this.credentials);
/// Provides a string description of the ExpirationException.
+ @override
String toString() =>
"OAuth2 credentials have expired and can't be refreshed.";
}
diff --git a/lib/src/handle_access_token_response.dart b/lib/src/handle_access_token_response.dart
index 851475a..7517af1 100644
--- a/lib/src/handle_access_token_response.dart
+++ b/lib/src/handle_access_token_response.dart
@@ -13,7 +13,7 @@
///
/// This allows credential expiration checks to remain valid for a reasonable
/// amount of time.
-const _expirationGrace = const Duration(seconds: 10);
+const _expirationGrace = Duration(seconds: 10);
/// Handles a response from the authorization server that contains an access
/// token.
@@ -32,7 +32,8 @@
/// [standard JSON response]: https://tools.ietf.org/html/rfc6749#section-5.1
Credentials handleAccessTokenResponse(http.Response response, Uri tokenEndpoint,
DateTime startTime, List<String> scopes, String delimiter,
- {Map<String, dynamic> getParameters(MediaType contentType, String body)}) {
+ {Map<String, dynamic> Function(MediaType contentType, String body)
+ getParameters}) {
getParameters ??= parseJsonParameters;
try {
@@ -42,18 +43,18 @@
var contentTypeString = response.headers['content-type'];
if (contentTypeString == null) {
- throw new FormatException('Missing Content-Type string.');
+ throw FormatException('Missing Content-Type string.');
}
var parameters =
- getParameters(new MediaType.parse(contentTypeString), response.body);
+ getParameters(MediaType.parse(contentTypeString), response.body);
for (var requiredParameter in ['access_token', 'token_type']) {
if (!parameters.containsKey(requiredParameter)) {
- throw new FormatException(
+ throw FormatException(
'did not contain required parameter "$requiredParameter"');
} else if (parameters[requiredParameter] is! String) {
- throw new FormatException(
+ throw FormatException(
'required parameter "$requiredParameter" was not a string, was '
'"${parameters[requiredParameter]}"');
}
@@ -62,21 +63,22 @@
// TODO(nweiz): support the "mac" token type
// (http://tools.ietf.org/html/draft-ietf-oauth-v2-http-mac-01)
if (parameters['token_type'].toLowerCase() != 'bearer') {
- throw new FormatException(
+ throw FormatException(
'"$tokenEndpoint": unknown token type "${parameters['token_type']}"');
}
var expiresIn = parameters['expires_in'];
if (expiresIn != null && expiresIn is! int) {
- throw new FormatException(
+ throw FormatException(
'parameter "expires_in" was not an int, was "$expiresIn"');
}
for (var name in ['refresh_token', 'id_token', 'scope']) {
var value = parameters[name];
- if (value != null && value is! String)
- throw new FormatException(
+ if (value != null && value is! String) {
+ throw FormatException(
'parameter "$name" was not a string, was "$value"');
+ }
}
var scope = parameters['scope'] as String;
@@ -84,16 +86,16 @@
var expiration = expiresIn == null
? null
- : startTime.add(new Duration(seconds: expiresIn) - _expirationGrace);
+ : startTime.add(Duration(seconds: expiresIn) - _expirationGrace);
- return new Credentials(parameters['access_token'],
+ return Credentials(parameters['access_token'],
refreshToken: parameters['refresh_token'],
idToken: parameters['id_token'],
tokenEndpoint: tokenEndpoint,
scopes: scopes,
expiration: expiration);
} on FormatException catch (e) {
- throw new FormatException('Invalid OAuth response for "$tokenEndpoint": '
+ throw FormatException('Invalid OAuth response for "$tokenEndpoint": '
'${e.message}.\n\n${response.body}');
}
}
@@ -110,34 +112,33 @@
if (response.reasonPhrase != null && response.reasonPhrase.isNotEmpty) {
' ${response.reasonPhrase}';
}
- throw new FormatException('OAuth request for "$tokenEndpoint" failed '
+ throw FormatException('OAuth request for "$tokenEndpoint" failed '
'with status ${response.statusCode}$reason.\n\n${response.body}');
}
var contentTypeString = response.headers['content-type'];
var contentType =
- contentTypeString == null ? null : new MediaType.parse(contentTypeString);
+ contentTypeString == null ? null : MediaType.parse(contentTypeString);
var parameters = getParameters(contentType, response.body);
if (!parameters.containsKey('error')) {
- throw new FormatException('did not contain required parameter "error"');
+ throw FormatException('did not contain required parameter "error"');
} else if (parameters['error'] is! String) {
- throw new FormatException(
- 'required parameter "error" was not a string, was '
+ throw FormatException('required parameter "error" was not a string, was '
'"${parameters["error"]}"');
}
for (var name in ['error_description', 'error_uri']) {
var value = parameters[name];
- if (value != null && value is! String)
- throw new FormatException(
- 'parameter "$name" was not a string, was "$value"');
+ if (value != null && value is! String) {
+ throw FormatException('parameter "$name" was not a string, was "$value"');
+ }
}
var description = parameters['error_description'];
var uriString = parameters['error_uri'];
var uri = uriString == null ? null : Uri.parse(uriString);
- throw new AuthorizationException(parameters['error'], description, uri);
+ throw AuthorizationException(parameters['error'], description, uri);
}
diff --git a/lib/src/parameters.dart b/lib/src/parameters.dart
index 09ee5b7..e8290fc 100644
--- a/lib/src/parameters.dart
+++ b/lib/src/parameters.dart
@@ -7,7 +7,8 @@
import 'package:http_parser/http_parser.dart';
/// The type of a callback that parses parameters from an HTTP response.
-typedef Map<String, dynamic> GetParameters(MediaType contentType, String body);
+typedef GetParameters = Map<String, dynamic> Function(
+ MediaType contentType, String body);
/// Parses parameters from a response with a JSON body, as per the [OAuth2
/// spec][].
@@ -17,9 +18,9 @@
// The spec requires a content-type of application/json, but some endpoints
// (e.g. Dropbox) serve it as text/javascript instead.
if (contentType == null ||
- (contentType.mimeType != "application/json" &&
- contentType.mimeType != "text/javascript")) {
- throw new FormatException(
+ (contentType.mimeType != 'application/json' &&
+ contentType.mimeType != 'text/javascript')) {
+ throw FormatException(
'Content-Type was "$contentType", expected "application/json"');
}
@@ -28,6 +29,5 @@
return untypedParameters;
}
- throw new FormatException(
- 'Parameters must be a map, was "$untypedParameters"');
+ throw FormatException('Parameters must be a map, was "$untypedParameters"');
}
diff --git a/lib/src/resource_owner_password_grant.dart b/lib/src/resource_owner_password_grant.dart
index 174a3c0..118f7c9 100644
--- a/lib/src/resource_owner_password_grant.dart
+++ b/lib/src/resource_owner_password_grant.dart
@@ -53,15 +53,15 @@
CredentialsRefreshedCallback onCredentialsRefreshed,
http.Client httpClient,
String delimiter,
- Map<String, dynamic> getParameters(
- MediaType contentType, String body)}) async {
+ Map<String, dynamic> Function(MediaType contentType, String body)
+ getParameters}) async {
delimiter ??= ' ';
- var startTime = new DateTime.now();
+ var startTime = DateTime.now();
var body = {
- "grant_type": "password",
- "username": username,
- "password": password
+ 'grant_type': 'password',
+ 'username': username,
+ 'password': password
};
var headers = <String, String>{};
@@ -75,17 +75,18 @@
}
}
- if (scopes != null && scopes.isNotEmpty)
+ if (scopes != null && scopes.isNotEmpty) {
body['scope'] = scopes.join(delimiter);
+ }
- if (httpClient == null) httpClient = new http.Client();
+ httpClient ??= http.Client();
var response = await httpClient.post(authorizationEndpoint,
headers: headers, body: body);
var credentials = await handleAccessTokenResponse(
response, authorizationEndpoint, startTime, scopes, delimiter,
getParameters: getParameters);
- return new Client(credentials,
+ return Client(credentials,
identifier: identifier,
secret: secret,
httpClient: httpClient,
diff --git a/lib/src/utils.dart b/lib/src/utils.dart
index 6c3453f..50a925a 100644
--- a/lib/src/utils.dart
+++ b/lib/src/utils.dart
@@ -7,9 +7,9 @@
/// Adds additional query parameters to [url], overwriting the original
/// parameters if a name conflict occurs.
Uri addQueryParameters(Uri url, Map<String, String> parameters) => url.replace(
- queryParameters: new Map.from(url.queryParameters)..addAll(parameters));
+ queryParameters: Map.from(url.queryParameters)..addAll(parameters));
String basicAuthHeader(String identifier, String secret) {
- var userPass = Uri.encodeFull(identifier) + ":" + Uri.encodeFull(secret);
- return "Basic " + base64Encode(ascii.encode(userPass));
+ var userPass = Uri.encodeFull(identifier) + ':' + Uri.encodeFull(secret);
+ return 'Basic ' + base64Encode(ascii.encode(userPass));
}
diff --git a/test/authorization_code_grant_test.dart b/test/authorization_code_grant_test.dart
index 2fcf36b..4909bf5 100644
--- a/test/authorization_code_grant_test.dart
+++ b/test/authorization_code_grant_test.dart
@@ -17,8 +17,8 @@
ExpectClient client;
oauth2.AuthorizationCodeGrant grant;
setUp(() {
- client = new ExpectClient();
- grant = new oauth2.AuthorizationCodeGrant(
+ client = ExpectClient();
+ grant = oauth2.AuthorizationCodeGrant(
'identifier',
Uri.parse('https://example.com/authorization'),
Uri.parse('https://example.com/token'),
@@ -55,7 +55,7 @@
});
test('separates scopes with the correct delimiter', () {
- var grant = new oauth2.AuthorizationCodeGrant(
+ var grant = oauth2.AuthorizationCodeGrant(
'identifier',
Uri.parse('https://example.com/authorization'),
Uri.parse('https://example.com/token'),
@@ -92,7 +92,7 @@
});
test('merges with existing query parameters', () {
- grant = new oauth2.AuthorizationCodeGrant(
+ grant = oauth2.AuthorizationCodeGrant(
'identifier',
Uri.parse('https://example.com/authorization?query=value'),
Uri.parse('https://example.com/token'),
@@ -171,9 +171,9 @@
'code_verifier', matches(r'[A-Za-z0-9\-\.\_\~]{128}'))
]));
expect(request.headers,
- containsPair("Authorization", "Basic aWRlbnRpZmllcjpzZWNyZXQ="));
+ containsPair('Authorization', 'Basic aWRlbnRpZmllcjpzZWNyZXQ='));
- return new Future.value(new http.Response(
+ return Future.value(http.Response(
jsonEncode({
'access_token': 'access token',
'token_type': 'bearer',
@@ -215,9 +215,9 @@
'code_verifier', matches(r'[A-Za-z0-9\-\.\_\~]{128}'))
]));
expect(request.headers,
- containsPair("Authorization", "Basic aWRlbnRpZmllcjpzZWNyZXQ="));
+ containsPair('Authorization', 'Basic aWRlbnRpZmllcjpzZWNyZXQ='));
- return new Future.value(new http.Response(
+ return Future.value(http.Response(
jsonEncode({
'access_token': 'access token',
'token_type': 'bearer',
@@ -234,10 +234,10 @@
});
});
- group("with basicAuth: false", () {
+ group('with basicAuth: false', () {
setUp(() {
- client = new ExpectClient();
- grant = new oauth2.AuthorizationCodeGrant(
+ client = ExpectClient();
+ grant = oauth2.AuthorizationCodeGrant(
'identifier',
Uri.parse('https://example.com/authorization'),
Uri.parse('https://example.com/token'),
@@ -264,7 +264,7 @@
containsPair('client_secret', 'secret')
]));
- return new Future.value(new http.Response(
+ return Future.value(http.Response(
jsonEncode({
'access_token': 'access token',
'token_type': 'bearer',
@@ -296,7 +296,7 @@
containsPair('client_secret', 'secret')
]));
- return new Future.value(new http.Response(
+ return Future.value(http.Response(
jsonEncode({
'access_token': 'access token',
'token_type': 'bearer',
@@ -316,7 +316,7 @@
group('onCredentialsRefreshed', () {
test('is correctly propagated', () async {
var isCallbackInvoked = false;
- var grant = new oauth2.AuthorizationCodeGrant(
+ var grant = oauth2.AuthorizationCodeGrant(
'identifier',
Uri.parse('https://example.com/authorization'),
Uri.parse('https://example.com/token'),
@@ -328,12 +328,12 @@
grant.getAuthorizationUrl(redirectUrl);
client.expectRequest((request) {
- return new Future.value(new http.Response(
+ return Future.value(http.Response(
jsonEncode({
'access_token': 'access token',
'token_type': 'bearer',
- "expires_in": -3600,
- "refresh_token": "refresh token",
+ 'expires_in': -3600,
+ 'refresh_token': 'refresh token',
}),
200,
headers: {'content-type': 'application/json'}));
@@ -342,7 +342,7 @@
var oauth2Client = await grant.handleAuthorizationCode('auth code');
client.expectRequest((request) {
- return new Future.value(new http.Response(
+ return Future.value(http.Response(
jsonEncode(
{'access_token': 'new access token', 'token_type': 'bearer'}),
200,
@@ -350,10 +350,10 @@
});
client.expectRequest((request) {
- return new Future.value(new http.Response('good job', 200));
+ return Future.value(http.Response('good job', 200));
});
- await oauth2Client.read(Uri.parse("http://example.com/resource"));
+ await oauth2Client.read(Uri.parse('http://example.com/resource'));
expect(isCallbackInvoked, equals(true));
});
diff --git a/test/client_credentials_grant_test.dart b/test/client_credentials_grant_test.dart
index 062414d..9e27c9e 100644
--- a/test/client_credentials_grant_test.dart
+++ b/test/client_credentials_grant_test.dart
@@ -2,7 +2,7 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
-@TestOn("vm")
+@TestOn('vm')
import 'dart:convert';
@@ -13,10 +13,10 @@
import 'utils.dart';
final success = jsonEncode({
- "access_token": "2YotnFZFEjr1zCsicMWpAA",
- "token_type": "bearer",
- "expires_in": 3600,
- "refresh_token": "tGzv3JOkF0XG5Qx2TlKWIA",
+ 'access_token': '2YotnFZFEjr1zCsicMWpAA',
+ 'token_type': 'bearer',
+ 'expires_in': 3600,
+ 'refresh_token': 'tGzv3JOkF0XG5Qx2TlKWIA',
});
var auth = 'Basic Y2xpZW50OnNlY3JldA==';
@@ -24,7 +24,7 @@
void main() {
var expectClient;
- setUp(() => expectClient = new ExpectClient());
+ setUp(() => expectClient = ExpectClient());
group('basic', () {
test('builds correct request with client when using basic auth for client',
@@ -32,7 +32,7 @@
expectClient.expectRequest((request) async {
expect(auth, equals(request.headers['authorization']));
expect(request.bodyFields['grant_type'], equals('client_credentials'));
- return new http.Response(success, 200,
+ return http.Response(success, 200,
headers: {'content-type': 'application/json'});
});
@@ -50,7 +50,7 @@
expect(request.bodyFields['grant_type'], equals('client_credentials'));
expect(request.bodyFields['client_id'], equals('client'));
expect(request.bodyFields['client_secret'], equals('secret'));
- return new http.Response(success, 200,
+ return http.Response(success, 200,
headers: {'content-type': 'application/json'});
});
@@ -66,7 +66,7 @@
expect(auth, equals(request.headers['authorization']));
expect(request.bodyFields['grant_type'], equals('client_credentials'));
expect(request.bodyFields['scope'], equals('one two'));
- return new http.Response(success, 200,
+ return http.Response(success, 200,
headers: {'content-type': 'application/json'});
});
@@ -81,7 +81,7 @@
expectClient.expectRequest((request) async {
expect(request.bodyFields['grant_type'], equals('client_credentials'));
expect(request.bodyFields['scope'], equals('one,two'));
- return new http.Response(success, 200,
+ return http.Response(success, 200,
headers: {'content-type': 'application/json'});
});
@@ -97,7 +97,7 @@
expect(request.bodyFields['client_id'], equals('client'));
expect(request.bodyFields['client_secret'], equals('secret'));
expect(request.url.queryParameters['query'], equals('value'));
- return new http.Response(success, 200,
+ return http.Response(success, 200,
headers: {'content-type': 'application/json'});
});
diff --git a/test/client_test.dart b/test/client_test.dart
index 1f13d58..11b725c 100644
--- a/test/client_test.dart
+++ b/test/client_test.dart
@@ -11,20 +11,20 @@
import 'utils.dart';
-final Uri requestUri = Uri.parse("http://example.com/resource");
+final Uri requestUri = Uri.parse('http://example.com/resource');
final Uri tokenEndpoint = Uri.parse('http://example.com/token');
void main() {
var httpClient;
- setUp(() => httpClient = new ExpectClient());
+ setUp(() => httpClient = ExpectClient());
group('with expired credentials', () {
test("that can't be refreshed throws an ExpirationException on send", () {
- var expiration = new DateTime.now().subtract(new Duration(hours: 1));
+ var expiration = DateTime.now().subtract(Duration(hours: 1));
var credentials =
- new oauth2.Credentials('access token', expiration: expiration);
- var client = new oauth2.Client(credentials,
+ oauth2.Credentials('access token', expiration: expiration);
+ var client = oauth2.Client(credentials,
identifier: 'identifier', secret: 'secret', httpClient: httpClient);
expect(client.get(requestUri),
@@ -32,20 +32,20 @@
});
test(
- "that can be refreshed refreshes the credentials and sends the "
- "request", () async {
- var expiration = new DateTime.now().subtract(new Duration(hours: 1));
- var credentials = new oauth2.Credentials('access token',
+ 'that can be refreshed refreshes the credentials and sends the '
+ 'request', () async {
+ var expiration = DateTime.now().subtract(Duration(hours: 1));
+ var credentials = oauth2.Credentials('access token',
refreshToken: 'refresh token',
tokenEndpoint: tokenEndpoint,
expiration: expiration);
- var client = new oauth2.Client(credentials,
+ 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 new Future.value(new http.Response(
+ return Future.value(http.Response(
jsonEncode(
{'access_token': 'new access token', 'token_type': 'bearer'}),
200,
@@ -58,22 +58,22 @@
expect(request.headers['authorization'],
equals('Bearer new access token'));
- return new Future.value(new http.Response('good job', 200));
+ return Future.value(http.Response('good job', 200));
});
await client.read(requestUri);
expect(client.credentials.accessToken, equals('new access token'));
});
- test("that onCredentialsRefreshed is called", () async {
+ test('that onCredentialsRefreshed is called', () async {
var callbackCalled = false;
- var expiration = new DateTime.now().subtract(new Duration(hours: 1));
- var credentials = new oauth2.Credentials('access token',
+ var expiration = DateTime.now().subtract(Duration(hours: 1));
+ var credentials = oauth2.Credentials('access token',
refreshToken: 'refresh token',
tokenEndpoint: tokenEndpoint,
expiration: expiration);
- var client = new oauth2.Client(credentials,
+ var client = oauth2.Client(credentials,
identifier: 'identifier',
secret: 'secret',
httpClient: httpClient, onCredentialsRefreshed: (credentials) {
@@ -82,7 +82,7 @@
});
httpClient.expectRequest((request) {
- return new Future.value(new http.Response(
+ return Future.value(http.Response(
jsonEncode(
{'access_token': 'new access token', 'token_type': 'bearer'}),
200,
@@ -90,7 +90,7 @@
});
httpClient.expectRequest((request) {
- return new Future.value(new http.Response('good job', 200));
+ return Future.value(http.Response('good job', 200));
});
await client.read(requestUri);
@@ -99,9 +99,9 @@
});
group('with valid credentials', () {
- test("sends a request with bearer authorization", () {
- var credentials = new oauth2.Credentials('access token');
- var client = new oauth2.Client(credentials,
+ test('sends a request with bearer authorization', () {
+ var credentials = oauth2.Credentials('access token');
+ var client = oauth2.Client(credentials,
identifier: 'identifier', secret: 'secret', httpClient: httpClient);
httpClient.expectRequest((request) {
@@ -109,22 +109,22 @@
expect(request.url.toString(), equals(requestUri.toString()));
expect(request.headers['authorization'], equals('Bearer access token'));
- return new Future.value(new http.Response('good job', 200));
+ return Future.value(http.Response('good job', 200));
});
expect(client.read(requestUri), completion(equals('good job')));
});
- test("can manually refresh the credentials", () async {
- var credentials = new oauth2.Credentials('access token',
+ test('can manually refresh the credentials', () async {
+ var credentials = oauth2.Credentials('access token',
refreshToken: 'refresh token', tokenEndpoint: tokenEndpoint);
- var client = new oauth2.Client(credentials,
+ 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 new Future.value(new http.Response(
+ return Future.value(http.Response(
jsonEncode(
{'access_token': 'new access token', 'token_type': 'bearer'}),
200,
@@ -136,8 +136,8 @@
});
test("without a refresh token can't manually refresh the credentials", () {
- var credentials = new oauth2.Credentials('access token');
- var client = new oauth2.Client(credentials,
+ var credentials = oauth2.Credentials('access token');
+ var client = oauth2.Client(credentials,
identifier: 'identifier', secret: 'secret', httpClient: httpClient);
expect(client.refreshCredentials(), throwsA(isStateError));
@@ -146,8 +146,8 @@
group('with invalid credentials', () {
test('throws an AuthorizationException for a 401 response', () {
- var credentials = new oauth2.Credentials('access token');
- var client = new oauth2.Client(credentials,
+ var credentials = oauth2.Credentials('access token');
+ var client = oauth2.Client(credentials,
identifier: 'identifier', secret: 'secret', httpClient: httpClient);
httpClient.expectRequest((request) {
@@ -157,7 +157,7 @@
var authenticate = 'Bearer error="invalid_token", error_description='
'"Something is terribly wrong."';
- return new Future.value(new http.Response('bad job', 401,
+ return Future.value(http.Response('bad job', 401,
headers: {'www-authenticate': authenticate}));
});
@@ -166,8 +166,8 @@
});
test('passes through a 401 response without www-authenticate', () async {
- var credentials = new oauth2.Credentials('access token');
- var client = new oauth2.Client(credentials,
+ var credentials = oauth2.Credentials('access token');
+ var client = oauth2.Client(credentials,
identifier: 'identifier', secret: 'secret', httpClient: httpClient);
httpClient.expectRequest((request) {
@@ -175,7 +175,7 @@
expect(request.url.toString(), equals(requestUri.toString()));
expect(request.headers['authorization'], equals('Bearer access token'));
- return new Future.value(new http.Response('bad job', 401));
+ return Future.value(http.Response('bad job', 401));
});
expect((await client.get(requestUri)).statusCode, equals(401));
@@ -183,8 +183,8 @@
test('passes through a 401 response with invalid www-authenticate',
() async {
- var credentials = new oauth2.Credentials('access token');
- var client = new oauth2.Client(credentials,
+ var credentials = oauth2.Credentials('access token');
+ var client = oauth2.Client(credentials,
identifier: 'identifier', secret: 'secret', httpClient: httpClient);
httpClient.expectRequest((request) {
@@ -194,7 +194,7 @@
var authenticate = 'Bearer error="invalid_token" error_description='
'"Something is terribly wrong."';
- return new Future.value(new http.Response('bad job', 401,
+ return Future.value(http.Response('bad job', 401,
headers: {'www-authenticate': authenticate}));
});
@@ -203,8 +203,8 @@
test('passes through a 401 response with non-bearer www-authenticate',
() async {
- var credentials = new oauth2.Credentials('access token');
- var client = new oauth2.Client(credentials,
+ var credentials = oauth2.Credentials('access token');
+ var client = oauth2.Client(credentials,
identifier: 'identifier', secret: 'secret', httpClient: httpClient);
httpClient.expectRequest((request) {
@@ -212,7 +212,7 @@
expect(request.url.toString(), equals(requestUri.toString()));
expect(request.headers['authorization'], equals('Bearer access token'));
- return new Future.value(new http.Response('bad job', 401,
+ return Future.value(http.Response('bad job', 401,
headers: {'www-authenticate': 'Digest'}));
});
@@ -221,8 +221,8 @@
test('passes through a 401 response with non-OAuth2 www-authenticate',
() async {
- var credentials = new oauth2.Credentials('access token');
- var client = new oauth2.Client(credentials,
+ var credentials = oauth2.Credentials('access token');
+ var client = oauth2.Client(credentials,
identifier: 'identifier', secret: 'secret', httpClient: httpClient);
httpClient.expectRequest((request) {
@@ -230,7 +230,7 @@
expect(request.url.toString(), equals(requestUri.toString()));
expect(request.headers['authorization'], equals('Bearer access token'));
- return new Future.value(new http.Response('bad job', 401,
+ return Future.value(http.Response('bad job', 401,
headers: {'www-authenticate': 'Bearer'}));
});
diff --git a/test/credentials_test.dart b/test/credentials_test.dart
index 386f948..1b3caa5 100644
--- a/test/credentials_test.dart
+++ b/test/credentials_test.dart
@@ -15,30 +15,30 @@
void main() {
var httpClient;
- setUp(() => httpClient = new ExpectClient());
+ setUp(() => httpClient = ExpectClient());
test('is not expired if no expiration exists', () {
- var credentials = new oauth2.Credentials('access token');
+ var credentials = oauth2.Credentials('access token');
expect(credentials.isExpired, isFalse);
});
test('is not expired if the expiration is in the future', () {
- var expiration = new DateTime.now().add(new Duration(hours: 1));
+ var expiration = DateTime.now().add(Duration(hours: 1));
var credentials =
- new oauth2.Credentials('access token', expiration: expiration);
+ oauth2.Credentials('access token', expiration: expiration);
expect(credentials.isExpired, isFalse);
});
test('is expired if the expiration is in the past', () {
- var expiration = new DateTime.now().subtract(new Duration(hours: 1));
+ var expiration = DateTime.now().subtract(Duration(hours: 1));
var credentials =
- new oauth2.Credentials('access token', expiration: expiration);
+ oauth2.Credentials('access token', expiration: expiration);
expect(credentials.isExpired, isTrue);
});
test("can't refresh without a refresh token", () {
var credentials =
- new oauth2.Credentials('access token', tokenEndpoint: tokenEndpoint);
+ oauth2.Credentials('access token', tokenEndpoint: tokenEndpoint);
expect(credentials.canRefresh, false);
expect(
@@ -49,7 +49,7 @@
test("can't refresh without a token endpoint", () {
var credentials =
- new oauth2.Credentials('access token', refreshToken: 'refresh token');
+ oauth2.Credentials('access token', refreshToken: 'refresh token');
expect(credentials.canRefresh, false);
expect(
@@ -58,8 +58,8 @@
throwsStateError);
});
- test("can refresh with a refresh token and a token endpoint", () async {
- var credentials = new oauth2.Credentials('access token',
+ test('can refresh with a refresh token and a token endpoint', () async {
+ var credentials = oauth2.Credentials('access token',
refreshToken: 'refresh token',
tokenEndpoint: tokenEndpoint,
scopes: ['scope1', 'scope2']);
@@ -71,16 +71,16 @@
expect(
request.bodyFields,
equals({
- "grant_type": "refresh_token",
- "refresh_token": "refresh token",
- "scope": "scope1 scope2"
+ 'grant_type': 'refresh_token',
+ 'refresh_token': 'refresh token',
+ 'scope': 'scope1 scope2'
}));
expect(
request.headers,
- containsPair("Authorization",
- "Basic aWQlQzMlQUJudCVDNCVBQmZpZXI6cyVDMyVBQmNyZXQ="));
+ containsPair('Authorization',
+ 'Basic aWQlQzMlQUJudCVDNCVBQmZpZXI6cyVDMyVBQmNyZXQ='));
- return new Future.value(new http.Response(
+ return Future.value(http.Response(
jsonEncode({
'access_token': 'new access token',
'token_type': 'bearer',
@@ -97,14 +97,14 @@
});
test('sets proper scope string when using custom delimiter', () async {
- var credentials = new oauth2.Credentials('access token',
+ var credentials = oauth2.Credentials('access token',
refreshToken: 'refresh token',
tokenEndpoint: tokenEndpoint,
scopes: ['scope1', 'scope2'],
delimiter: ',');
httpClient.expectRequest((http.Request request) {
expect(request.bodyFields['scope'], equals('scope1,scope2'));
- return new Future.value(new http.Response(
+ return Future.value(http.Response(
jsonEncode({
'access_token': 'new access token',
'token_type': 'bearer',
@@ -117,8 +117,8 @@
identifier: 'idëntīfier', secret: 'sëcret', httpClient: httpClient);
});
- test("can refresh without a client secret", () async {
- var credentials = new oauth2.Credentials('access token',
+ test('can refresh without a client secret', () async {
+ var credentials = oauth2.Credentials('access token',
refreshToken: 'refresh token',
tokenEndpoint: tokenEndpoint,
scopes: ['scope1', 'scope2']);
@@ -130,13 +130,13 @@
expect(
request.bodyFields,
equals({
- "grant_type": "refresh_token",
- "refresh_token": "refresh token",
- "scope": "scope1 scope2",
- "client_id": "identifier"
+ 'grant_type': 'refresh_token',
+ 'refresh_token': 'refresh token',
+ 'scope': 'scope1 scope2',
+ 'client_id': 'identifier'
}));
- return new Future.value(new http.Response(
+ return Future.value(http.Response(
jsonEncode({
'access_token': 'new access token',
'token_type': 'bearer',
@@ -152,8 +152,8 @@
expect(credentials.refreshToken, equals('new refresh token'));
});
- test("can refresh without client authentication", () async {
- var credentials = new oauth2.Credentials('access token',
+ test('can refresh without client authentication', () async {
+ var credentials = oauth2.Credentials('access token',
refreshToken: 'refresh token',
tokenEndpoint: tokenEndpoint,
scopes: ['scope1', 'scope2']);
@@ -165,12 +165,12 @@
expect(
request.bodyFields,
equals({
- "grant_type": "refresh_token",
- "refresh_token": "refresh token",
- "scope": "scope1 scope2"
+ 'grant_type': 'refresh_token',
+ 'refresh_token': 'refresh token',
+ 'scope': 'scope1 scope2'
}));
- return new Future.value(new http.Response(
+ return Future.value(http.Response(
jsonEncode({
'access_token': 'new access token',
'token_type': 'bearer',
@@ -186,7 +186,7 @@
});
test("uses the old refresh token if a new one isn't provided", () async {
- var credentials = new oauth2.Credentials('access token',
+ var credentials = oauth2.Credentials('access token',
refreshToken: 'refresh token', tokenEndpoint: tokenEndpoint);
expect(credentials.canRefresh, true);
@@ -196,15 +196,15 @@
expect(
request.bodyFields,
equals({
- "grant_type": "refresh_token",
- "refresh_token": "refresh token"
+ 'grant_type': 'refresh_token',
+ 'refresh_token': 'refresh token'
}));
expect(
request.headers,
- containsPair("Authorization",
- "Basic aWQlQzMlQUJudCVDNCVBQmZpZXI6cyVDMyVBQmNyZXQ="));
+ containsPair('Authorization',
+ 'Basic aWQlQzMlQUJudCVDNCVBQmZpZXI6cyVDMyVBQmNyZXQ='));
- return new Future.value(new http.Response(
+ return Future.value(http.Response(
jsonEncode(
{'access_token': 'new access token', 'token_type': 'bearer'}),
200,
@@ -217,8 +217,8 @@
expect(credentials.refreshToken, equals('refresh token'));
});
- test("uses form-field authentication if basicAuth is false", () async {
- var credentials = new oauth2.Credentials('access token',
+ test('uses form-field authentication if basicAuth is false', () async {
+ var credentials = oauth2.Credentials('access token',
refreshToken: 'refresh token',
tokenEndpoint: tokenEndpoint,
scopes: ['scope1', 'scope2']);
@@ -230,14 +230,14 @@
expect(
request.bodyFields,
equals({
- "grant_type": "refresh_token",
- "refresh_token": "refresh token",
- "scope": "scope1 scope2",
- "client_id": "idëntīfier",
- "client_secret": "sëcret"
+ 'grant_type': 'refresh_token',
+ 'refresh_token': 'refresh token',
+ 'scope': 'scope1 scope2',
+ 'client_id': 'idëntīfier',
+ 'client_secret': 'sëcret'
}));
- return new Future.value(new http.Response(
+ return Future.value(http.Response(
jsonEncode({
'access_token': 'new access token',
'token_type': 'bearer',
@@ -256,25 +256,25 @@
expect(credentials.refreshToken, equals('new refresh token'));
});
- group("fromJson", () {
+ group('fromJson', () {
oauth2.Credentials fromMap(Map map) =>
- new oauth2.Credentials.fromJson(jsonEncode(map));
+ oauth2.Credentials.fromJson(jsonEncode(map));
- test("should load the same credentials from toJson", () {
+ test('should load the same credentials from toJson', () {
// Round the expiration down to milliseconds since epoch, since that's
// what the credentials file stores. Otherwise sub-millisecond time gets
// in the way.
- var expiration = new DateTime.now().subtract(new Duration(hours: 1));
- expiration = new DateTime.fromMillisecondsSinceEpoch(
+ var expiration = DateTime.now().subtract(Duration(hours: 1));
+ expiration = DateTime.fromMillisecondsSinceEpoch(
expiration.millisecondsSinceEpoch);
- var credentials = new oauth2.Credentials('access token',
+ var credentials = oauth2.Credentials('access token',
refreshToken: 'refresh token',
idToken: 'id token',
tokenEndpoint: tokenEndpoint,
scopes: ['scope1', 'scope2'],
expiration: expiration);
- var reloaded = new oauth2.Credentials.fromJson(credentials.toJson());
+ var reloaded = oauth2.Credentials.fromJson(credentials.toJson());
expect(reloaded.accessToken, equals(credentials.accessToken));
expect(reloaded.refreshToken, equals(credentials.refreshToken));
@@ -285,46 +285,45 @@
expect(reloaded.expiration, equals(credentials.expiration));
});
- test("should throw a FormatException for invalid JSON", () {
- expect(() => new oauth2.Credentials.fromJson("foo bar"),
- throwsFormatException);
+ test('should throw a FormatException for invalid JSON', () {
+ expect(
+ () => oauth2.Credentials.fromJson('foo bar'), throwsFormatException);
});
test("should throw a FormatException for JSON that's not a map", () {
- expect(
- () => new oauth2.Credentials.fromJson("null"), throwsFormatException);
+ expect(() => oauth2.Credentials.fromJson('null'), throwsFormatException);
});
- test("should throw a FormatException if there is no accessToken", () {
+ test('should throw a FormatException if there is no accessToken', () {
expect(() => fromMap({}), throwsFormatException);
});
- test("should throw a FormatException if accessToken is not a string", () {
- expect(() => fromMap({"accessToken": 12}), throwsFormatException);
+ test('should throw a FormatException if accessToken is not a string', () {
+ expect(() => fromMap({'accessToken': 12}), throwsFormatException);
});
- test("should throw a FormatException if refreshToken is not a string", () {
- expect(() => fromMap({"accessToken": "foo", "refreshToken": 12}),
+ test('should throw a FormatException if refreshToken is not a string', () {
+ expect(() => fromMap({'accessToken': 'foo', 'refreshToken': 12}),
throwsFormatException);
});
- test("should throw a FormatException if idToken is not a string", () {
- expect(() => fromMap({"accessToken": "foo", "idToken": 12}),
+ test('should throw a FormatException if idToken is not a string', () {
+ expect(() => fromMap({'accessToken': 'foo', 'idToken': 12}),
throwsFormatException);
});
- test("should throw a FormatException if tokenEndpoint is not a string", () {
- expect(() => fromMap({"accessToken": "foo", "tokenEndpoint": 12}),
+ test('should throw a FormatException if tokenEndpoint is not a string', () {
+ expect(() => fromMap({'accessToken': 'foo', 'tokenEndpoint': 12}),
throwsFormatException);
});
- test("should throw a FormatException if scopes is not a list", () {
- expect(() => fromMap({"accessToken": "foo", "scopes": 12}),
+ test('should throw a FormatException if scopes is not a list', () {
+ expect(() => fromMap({'accessToken': 'foo', 'scopes': 12}),
throwsFormatException);
});
- test("should throw a FormatException if expiration is not an int", () {
- expect(() => fromMap({"accessToken": "foo", "expiration": "12"}),
+ test('should throw a FormatException if expiration is not an int', () {
+ expect(() => fromMap({'accessToken': 'foo', 'expiration': '12'}),
throwsFormatException);
});
});
diff --git a/test/handle_access_token_response_test.dart b/test/handle_access_token_response_test.dart
index 1556164..10aef48 100644
--- a/test/handle_access_token_response_test.dart
+++ b/test/handle_access_token_response_test.dart
@@ -13,14 +13,14 @@
import 'utils.dart';
-final Uri tokenEndpoint = Uri.parse("https://example.com/token");
+final Uri tokenEndpoint = Uri.parse('https://example.com/token');
-final DateTime startTime = new DateTime.now();
+final DateTime startTime = DateTime.now();
oauth2.Credentials handle(http.Response response,
{GetParameters getParameters}) =>
handleAccessTokenResponse(
- response, tokenEndpoint, startTime, ["scope"], ' ',
+ response, tokenEndpoint, startTime, ['scope'], ' ',
getParameters: getParameters);
void main() {
@@ -29,9 +29,9 @@
{String body = '{"error": "invalid_request"}',
int statusCode = 400,
Map<String, String> headers = const {
- "content-type": "application/json"
+ 'content-type': 'application/json'
}}) =>
- handle(new http.Response(body, statusCode, headers: headers));
+ handle(http.Response(body, statusCode, headers: headers));
test('causes an AuthorizationException', () {
expect(() => handleError(), throwsAuthorizationException);
@@ -81,14 +81,14 @@
expect(
() => handleError(
body: jsonEncode(
- {"error": "invalid_request", "error_description": 12})),
+ {'error': 'invalid_request', 'error_description': 12})),
throwsFormatException);
});
test('with a non-string error_uri causes a FormatException', () {
expect(
() => handleError(
- body: jsonEncode({"error": "invalid_request", "error_uri": 12})),
+ body: jsonEncode({'error': 'invalid_request', 'error_uri': 12})),
throwsFormatException);
});
@@ -96,8 +96,8 @@
expect(
() => handleError(
body: jsonEncode({
- "error": "invalid_request",
- "error_description": "description"
+ 'error': 'invalid_request',
+ 'error_description': 'description'
})),
throwsAuthorizationException);
});
@@ -106,8 +106,8 @@
expect(
() => handleError(
body: jsonEncode({
- "error": "invalid_request",
- "error_uri": "http://example.com/error"
+ 'error': 'invalid_request',
+ 'error_uri': 'http://example.com/error'
})),
throwsAuthorizationException);
});
@@ -115,13 +115,13 @@
group('a success response', () {
oauth2.Credentials handleSuccess(
- {String contentType = "application/json",
+ {String contentType = 'application/json',
accessToken = 'access token',
tokenType = 'bearer',
expiresIn,
refreshToken,
scope}) {
- return handle(new http.Response(
+ return handle(http.Response(
jsonEncode({
'access_token': accessToken,
'token_type': tokenType,
@@ -166,7 +166,7 @@
var body = '_' +
jsonEncode({'token_type': 'bearer', 'access_token': 'access token'});
var credentials = handle(
- new http.Response(body, 200, headers: {'content-type': 'text/plain'}),
+ http.Response(body, 200, headers: {'content-type': 'text/plain'}),
getParameters: (contentType, body) => jsonDecode(body.substring(1)));
expect(credentials.accessToken, equals('access token'));
expect(credentials.tokenEndpoint.toString(),
@@ -175,7 +175,7 @@
test('throws a FormatException if custom getParameters rejects response',
() {
- var response = new http.Response(
+ var response = http.Response(
jsonEncode({
'access_token': 'access token',
'token_type': 'bearer',
@@ -188,7 +188,7 @@
expect(
() => handle(response,
- getParameters: (contentType, body) => throw new FormatException(
+ getParameters: (contentType, body) => throw FormatException(
'unsupported content-type: $contentType')),
throwsFormatException);
});
@@ -210,11 +210,11 @@
});
test('with a non-"bearer" token type throws a FormatException', () {
- expect(() => handleSuccess(tokenType: "mac"), throwsFormatException);
+ expect(() => handleSuccess(tokenType: 'mac'), throwsFormatException);
});
test('with a non-int expires-in throws a FormatException', () {
- expect(() => handleSuccess(expiresIn: "whenever"), throwsFormatException);
+ expect(() => handleSuccess(expiresIn: 'whenever'), throwsFormatException);
});
test(
@@ -230,8 +230,8 @@
});
test('with a refresh token sets the refresh token', () {
- var credentials = handleSuccess(refreshToken: "refresh me");
- expect(credentials.refreshToken, equals("refresh me"));
+ var credentials = handleSuccess(refreshToken: 'refresh me');
+ expect(credentials.refreshToken, equals('refresh me'));
});
test('with a non-string scope throws a FormatException', () {
@@ -239,12 +239,12 @@
});
test('with a scope sets the scopes', () {
- var credentials = handleSuccess(scope: "scope1 scope2");
- expect(credentials.scopes, equals(["scope1", "scope2"]));
+ var credentials = handleSuccess(scope: 'scope1 scope2');
+ expect(credentials.scopes, equals(['scope1', 'scope2']));
});
test('with a custom scope delimiter sets the scopes', () {
- var response = new http.Response(
+ var response = http.Response(
jsonEncode({
'access_token': 'access token',
'token_type': 'bearer',
@@ -262,13 +262,13 @@
group('a success response with a id_token', () {
oauth2.Credentials handleSuccess(
- {String contentType = "application/json",
+ {String contentType = 'application/json',
accessToken = 'access token',
tokenType = 'bearer',
expiresIn,
idToken = 'decode me',
scope}) {
- return handle(new http.Response(
+ return handle(http.Response(
jsonEncode({
'access_token': accessToken,
'token_type': tokenType,
@@ -285,8 +285,8 @@
});
test('with a id token sets the id token', () {
- var credentials = handleSuccess(idToken: "decode me");
- expect(credentials.idToken, equals("decode me"));
+ var credentials = handleSuccess(idToken: 'decode me');
+ expect(credentials.idToken, equals('decode me'));
});
});
}
diff --git a/test/resource_owner_password_grant_test.dart b/test/resource_owner_password_grant_test.dart
index acd76d1..c9afb65 100644
--- a/test/resource_owner_password_grant_test.dart
+++ b/test/resource_owner_password_grant_test.dart
@@ -2,7 +2,7 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
-@TestOn("vm")
+@TestOn('vm')
import 'dart:convert';
import 'dart:async';
@@ -13,10 +13,10 @@
import 'utils.dart';
final success = jsonEncode({
- "access_token": "2YotnFZFEjr1zCsicMWpAA",
- "token_type": "bearer",
- "expires_in": 3600,
- "refresh_token": "tGzv3JOkF0XG5Qx2TlKWIA",
+ 'access_token': '2YotnFZFEjr1zCsicMWpAA',
+ 'token_type': 'bearer',
+ 'expires_in': 3600,
+ 'refresh_token': 'tGzv3JOkF0XG5Qx2TlKWIA',
});
var auth = 'Basic Y2xpZW50OnNlY3JldA==';
@@ -24,7 +24,7 @@
void main() {
var expectClient;
- setUp(() => expectClient = new ExpectClient());
+ setUp(() => expectClient = ExpectClient());
group('basic', () {
test('builds correct request with client when using basic auth for client',
@@ -34,7 +34,7 @@
expect(request.bodyFields['grant_type'], equals('password'));
expect(request.bodyFields['username'], equals('username'));
expect(request.bodyFields['password'], equals('userpass'));
- return new http.Response(success, 200,
+ return http.Response(success, 200,
headers: {'content-type': 'application/json'});
});
@@ -48,12 +48,12 @@
test('passes the onCredentialsRefreshed callback to the client', () async {
expectClient.expectRequest((request) async {
- return new http.Response(
+ return http.Response(
jsonEncode({
- "access_token": "2YotnFZFEjr1zCsicMWpAA",
- "token_type": "bearer",
- "expires_in": -3600,
- "refresh_token": "tGzv3JOkF0XG5Qx2TlKWIA",
+ 'access_token': '2YotnFZFEjr1zCsicMWpAA',
+ 'token_type': 'bearer',
+ 'expires_in': -3600,
+ 'refresh_token': 'tGzv3JOkF0XG5Qx2TlKWIA',
}),
200,
headers: {'content-type': 'application/json'});
@@ -69,7 +69,7 @@
});
expectClient.expectRequest((request) {
- return new Future.value(new http.Response(
+ return Future.value(http.Response(
jsonEncode(
{'access_token': 'new access token', 'token_type': 'bearer'}),
200,
@@ -77,10 +77,10 @@
});
expectClient.expectRequest((request) {
- return new Future.value(new http.Response('good job', 200));
+ return Future.value(http.Response('good job', 200));
});
- await client.read(Uri.parse("http://example.com/resource"));
+ await client.read(Uri.parse('http://example.com/resource'));
expect(isCallbackInvoked, equals(true));
});
@@ -92,7 +92,7 @@
expect(request.bodyFields['client_secret'], equals('secret'));
expect(request.bodyFields['username'], equals('username'));
expect(request.bodyFields['password'], equals('userpass'));
- return new http.Response(success, 200,
+ return http.Response(success, 200,
headers: {'content-type': 'application/json'});
});
@@ -112,7 +112,7 @@
expect(request.bodyFields['username'], equals('username'));
expect(request.bodyFields['password'], equals('userpass'));
expect(request.bodyFields['scope'], equals('one two'));
- return new http.Response(success, 200,
+ return http.Response(success, 200,
headers: {'content-type': 'application/json'});
});
@@ -129,7 +129,7 @@
expect(request.bodyFields['username'], equals('username'));
expect(request.bodyFields['password'], equals('userpass'));
expect(request.bodyFields['scope'], equals('one,two'));
- return new http.Response(success, 200,
+ return http.Response(success, 200,
headers: {'content-type': 'application/json'});
});
@@ -148,7 +148,7 @@
expect(request.bodyFields['username'], equals('username'));
expect(request.bodyFields['password'], equals('userpass'));
expect(request.url.queryParameters['query'], equals('value'));
- return new http.Response(success, 200,
+ return http.Response(success, 200,
headers: {'content-type': 'application/json'});
});
diff --git a/test/utils.dart b/test/utils.dart
index 64d1eb8..528673c 100644
--- a/test/utils.dart
+++ b/test/utils.dart
@@ -14,17 +14,17 @@
final Queue<MockClientHandler> _handlers;
ExpectClient._(MockClientHandler fn)
- : _handlers = new Queue<MockClientHandler>(),
+ : _handlers = Queue<MockClientHandler>(),
super(fn);
factory ExpectClient() {
var client;
- client = new ExpectClient._((request) => client._handleRequest(request));
+ client = ExpectClient._((request) => client._handleRequest(request));
return client;
}
void expectRequest(MockClientHandler fn) {
- var completer = new Completer();
+ var completer = Completer();
expect(completer.future, completes);
_handlers.add((request) {
@@ -35,7 +35,7 @@
Future<http.Response> _handleRequest(http.Request request) {
if (_handlers.isEmpty) {
- return new Future.value(new http.Response('not found', 404));
+ return Future.value(http.Response('not found', 404));
} else {
return _handlers.removeFirst()(request);
}