Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(82)

Unified Diff: lib/src/handle_access_token_response.dart

Issue 1953643002: Fix all strong-mode warnings. (Closed) Base URL: git@github.com:dart-lang/oauth2.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lib/src/credentials.dart ('k') | lib/src/resource_owner_password_grant.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/handle_access_token_response.dart
diff --git a/lib/src/handle_access_token_response.dart b/lib/src/handle_access_token_response.dart
index 94d9487abf52b7443296f08d61bc0773552eedc3..cb9e17cf37eda6609fa729a5711a008b2269d6c3 100644
--- a/lib/src/handle_access_token_response.dart
+++ b/lib/src/handle_access_token_response.dart
@@ -4,6 +4,7 @@
import 'dart:convert';
+import 'package:collection/collection.dart';
import 'package:http/http.dart' as http;
import 'package:http_parser/http_parser.dart';
@@ -31,8 +32,10 @@ Credentials handleAccessTokenResponse(
validate(condition, message) =>
_validate(response, tokenEndpoint, condition, message);
- var contentType = response.headers['content-type'];
- if (contentType != null) contentType = new MediaType.parse(contentType);
+ var contentTypeString = response.headers['content-type'];
+ var contentType = contentTypeString == null
+ ? null
+ : new MediaType.parse(contentTypeString);
// The spec requires a content-type of application/json, but some endpoints
// (e.g. Dropbox) serve it as text/javascript instead.
@@ -41,9 +44,12 @@ Credentials handleAccessTokenResponse(
contentType.mimeType == "text/javascript"),
'content-type was "$contentType", expected "application/json"');
- var parameters;
+ Map<String, dynamic> parameters;
try {
- parameters = JSON.decode(response.body);
+ var untypedParameters = JSON.decode(response.body);
+ validate(untypedParameters is Map,
+ 'parameters must be a map, was "$parameters"');
+ parameters = DelegatingMap.typed(untypedParameters);
} on FormatException catch (_) {
validate(false, 'invalid JSON');
}
@@ -71,7 +77,7 @@ Credentials handleAccessTokenResponse(
'parameter "$name" was not a string, was "$value"');
}
- var scope = parameters['scope'];
+ var scope = parameters['scope'] as String;
if (scope != null) scopes = scope.split(" ");
var expiration = expiresIn == null ? null :
@@ -103,8 +109,11 @@ void _handleErrorResponse(http.Response response, Uri tokenEndpoint) {
'with status ${response.statusCode}$reason.\n\n${response.body}');
}
- var contentType = response.headers['content-type'];
- if (contentType != null) contentType = new MediaType.parse(contentType);
+ var contentTypeString = response.headers['content-type'];
+ var contentType = contentTypeString == null
+ ? null
+ : new MediaType.parse(contentTypeString);
+
validate(contentType != null && contentType.mimeType == "application/json",
'content-type was "$contentType", expected "application/json"');
« no previous file with comments | « lib/src/credentials.dart ('k') | lib/src/resource_owner_password_grant.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698