Skip to content

Commit

Permalink
Added text/javascript as a possible content-type response to the _val…
Browse files Browse the repository at this point in the history
…idate method

Some api provider like dropbox core api use text/javascript instead application/json as content-type response
BUG=
R=nweiz@google.com

Review URL: https://codereview.chromium.org//177093006

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@33001 260f80e4-7a28-3924-810f-c04153c831b5
  • Loading branch information
nex3 committed Feb 25, 2014
1 parent 29be7bf commit a5cc4f6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
7 changes: 6 additions & 1 deletion pkg/oauth2/lib/src/handle_access_token_response.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,12 @@ Credentials handleAccessTokenResponse(
if (contentType != null) {
contentType = ContentType.parse(contentType);
}
validate(contentType != null && contentType.value == "application/json",

// The spec requires a content-type of application/json, but some endpoints
// (e.g. Dropbox) serve it as text/javascript instead.
validate(contentType != null &&
(contentType.value == "application/json" ||
contentType.value == "text/javascript"),
'content-type was "$contentType", expected "application/json"');

var parameters;
Expand Down
5 changes: 5 additions & 0 deletions pkg/oauth2/test/handle_access_token_response_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,11 @@ void main() {
expect(credentials.accessToken, equals('access token'));
});

test('with a JavScript content-type returns the correct credentials', () {
var credentials = handleSuccess(contentType: 'text/javascript');
expect(credentials.accessToken, equals('access token'));
});

test('with a null access token throws a FormatException', () {
expect(() => handleSuccess(accessToken: null), throwsFormatException);
});
Expand Down

0 comments on commit a5cc4f6

Please sign in to comment.