Skip to content
This repository was archived by the owner on Aug 26, 2024. It is now read-only.

Support text/plain content type in handleAccessTokenResponse #20

Merged
merged 42 commits into from
Mar 26, 2018
Merged

Support text/plain content type in handleAccessTokenResponse #20

merged 42 commits into from
Mar 26, 2018

Conversation

thosakwe
Copy link
Contributor

@thosakwe thosakwe commented Jun 3, 2017

This should resolve dart-lang/tools#303.

@thosakwe
Copy link
Contributor Author

thosakwe commented Jun 3, 2017

I'm also going to modify this to support the application/x-www-form-urlencoded content type, as that's what GitHub sends by default.

@nex3
Copy link
Contributor

nex3 commented Jun 5, 2017

It looks like this converts all the line endings to Windows newlines, which causes a giant diff. Can you undo that?

@thosakwe
Copy link
Contributor Author

thosakwe commented Jun 5, 2017

Will do!!!

@thosakwe
Copy link
Contributor Author

Fixed!

Copy link
Contributor

@nex3 nex3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please run the formatter and merge with master.

@@ -57,6 +57,10 @@ class Credentials {
/// expiration date.
final DateTime expiration;

/// A function used to parse parameters out of responses from hosts that do not
/// respond with application/json or application/x-www-form-urlencoded bodies.
final Function getParameters;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should also have the full function type, and it should be private.

parameters = DelegatingMap.typed(untypedParameters);
} on FormatException {
validate(false, 'invalid JSON');
parameters = getParameters(contentTypeString, response.body);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems wrong that we're passing the full content type here, but only the mime type in _handleErrorResponse() below. Why not just pass in the parsed MediaType in both cases?

Also, if whatever we pass in can be null, that should be clearly documented.

import 'package:collection/collection.dart';
import 'package:http_parser/http_parser.dart';

typedef Map<String, dynamic> GetParameters(String contentType, String body);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this used anywhere?

if (condition) return;
throw new FormatException('Invalid OAuth response for "$tokenEndpoint": '
'$message.\n\n${response.body}');
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This still needs to exist; right now, validation outside of getParameters() won't include the token endpoint or the response body.


typedef Map<String, dynamic> GetParameters(String contentType, String body);

void validate(bool condition, String message) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's worth defining this versus just manually writing if statements in parseJsonParameters().

…ent-type strings, we are passing MediaTypes. Thus, if a content-type string is null, an ArgumentError will be thrown, instead of FormatException.
@thosakwe
Copy link
Contributor Author

Sorry this took me so long to get through, but finally made the requested changes.

I've changed one of the tests from expecting a FormatException to an ArgumentError; this is just because now instead of passing around content-type strings, we're passing MediaTypes.

@nex3
Copy link
Contributor

nex3 commented Mar 20, 2018

Please merge in the latest master—otherwise GitHub includes a bunch of formatting changes in the diff.

@thosakwe
Copy link
Contributor Author

Finally merged the master inwards

@nex3
Copy link
Contributor

nex3 commented Mar 20, 2018

Looks like you accidentally committed your .idea directory...

@thosakwe
Copy link
Contributor Author

Removed it now, sorry.

@nex3
Copy link
Contributor

nex3 commented Mar 21, 2018

It looks like your change is causing a browser test failure. Can you investigate?

@thosakwe
Copy link
Contributor Author

So, it looks like though an ArgumentError is thrown when the string passed to StringScanner.matches is null, in the browser, it throws a NullError (which I didn't even know existed?).

I'm wondering if it would be acceptable to change the check for throwsArgumentError to throws?

@nex3
Copy link
Contributor

nex3 commented Mar 23, 2018

The easiest thing to do would probably be to just keep explicitly throwing a ForamtException.

@thosakwe
Copy link
Contributor Author

Sounds good to me! Hopefully the build succeeds this time.

@nex3
Copy link
Contributor

nex3 commented Mar 26, 2018

Looks good! Thanks for all your work on this.

@nex3 nex3 merged commit 595cfc0 into dart-archive:master Mar 26, 2018
@thosakwe
Copy link
Contributor Author

Always happy to contribute!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

Successfully merging this pull request may close these issues.

Add workaround for Facebook oauth bug to oauth2 package
4 participants