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

Side by Side Diff: pkg/oauth2/lib/src/handle_access_token_response.dart

Issue 177093006: Added text/javascript as a possible content-type response to the _validate method (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 10 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library handle_access_token_response; 5 library handle_access_token_response;
6 6
7 import 'dart:io'; 7 import 'dart:io';
8 import 'dart:convert'; 8 import 'dart:convert';
9 9
10 import 'package:http/http.dart' as http; 10 import 'package:http/http.dart' as http;
(...skipping 16 matching lines...) Expand all
27 List<String> scopes) { 27 List<String> scopes) {
28 if (response.statusCode != 200) _handleErrorResponse(response, tokenEndpoint); 28 if (response.statusCode != 200) _handleErrorResponse(response, tokenEndpoint);
29 29
30 void validate(bool condition, String message) => 30 void validate(bool condition, String message) =>
31 _validate(response, tokenEndpoint, condition, message); 31 _validate(response, tokenEndpoint, condition, message);
32 32
33 var contentType = response.headers['content-type']; 33 var contentType = response.headers['content-type'];
34 if (contentType != null) { 34 if (contentType != null) {
35 contentType = ContentType.parse(contentType); 35 contentType = ContentType.parse(contentType);
36 } 36 }
37 validate(contentType != null && contentType.value == "application/json", 37 validate(contentType != null && (contentType.value == "application/json" || co ntentType.value == "text/javascript"),
38 'content-type was "$contentType", expected "application/json"'); 38 'content-type was "$contentType", expected "application/json" or "text/jav ascript"');
39 39
40 var parameters; 40 var parameters;
41 try { 41 try {
42 parameters = JSON.decode(response.body); 42 parameters = JSON.decode(response.body);
43 } on FormatException catch (e) { 43 } on FormatException catch (e) {
44 validate(false, 'invalid JSON'); 44 validate(false, 'invalid JSON');
45 } 45 }
46 46
47 for (var requiredParameter in ['access_token', 'token_type']) { 47 for (var requiredParameter in ['access_token', 'token_type']) {
48 validate(parameters.containsKey(requiredParameter), 48 validate(parameters.containsKey(requiredParameter),
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 133
134 void _validate( 134 void _validate(
135 http.Response response, 135 http.Response response,
136 Uri tokenEndpoint, 136 Uri tokenEndpoint,
137 bool condition, 137 bool condition,
138 String message) { 138 String message) {
139 if (condition) return; 139 if (condition) return;
140 throw new FormatException('Invalid OAuth response for "$tokenEndpoint": ' 140 throw new FormatException('Invalid OAuth response for "$tokenEndpoint": '
141 '$message.\n\n${response.body}'); 141 '$message.\n\n${response.body}');
142 } 142 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698