diff --git a/CHANGELOG.md b/CHANGELOG.md index c4d542e..a5a361d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## 1.0.6 +- Fixed parameter encoding + ## 1.0.5 - Allow `oauth_callback_confirmed=1` in addition to `oauth_callback_confirmed=true` - Add example diff --git a/lib/src/authorization_header.dart b/lib/src/authorization_header.dart index 3a8dcfe..a578f91 100644 --- a/lib/src/authorization_header.dart +++ b/lib/src/authorization_header.dart @@ -1,10 +1,10 @@ library authorization_header; +import 'client_credentials.dart'; +import 'credentials.dart'; // import 'package:uuid/uuid.dart'; import 'signature_method.dart'; -import 'client_credentials.dart'; -import 'credentials.dart'; /// A class describing Authorization Header. /// http://tools.ietf.org/html/rfc5849#section-3.5.1 @@ -60,6 +60,21 @@ class AuthorizationHeader { return authHeader; } + /// Percent-encodes the [param]. + /// + /// All characters except uppercase and lowercase letters, digits and the + /// characters `-_.~` are percent-encoded. + /// + /// See https://oauth.net/core/1.0a/#encoding_parameters. + String _encodeParam(String param) { + return Uri.encodeComponent(param) + .replaceAll('!', '%21') + .replaceAll('*', '%2A') + .replaceAll("'", '%27') + .replaceAll('(', '%28') + .replaceAll(')', '%29'); + } + /// Create signature in ways referred from /// https://dev.twitter.com/docs/auth/creating-signature. String _createSignature( @@ -78,10 +93,10 @@ class AuthorizationHeader { // that will be signed. final Map encodedParams = {}; params.forEach((String k, String v) { - encodedParams[Uri.encodeComponent(k)] = Uri.encodeComponent(v); + encodedParams[_encodeParam(k)] = _encodeParam(v); }); uri.queryParameters.forEach((String k, String v) { - encodedParams[Uri.encodeComponent(k)] = Uri.encodeComponent(v); + encodedParams[_encodeParam(k)] = _encodeParam(v); }); params.remove('realm'); diff --git a/pubspec.yaml b/pubspec.yaml index 5166f16..9a8daf2 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,5 +1,5 @@ name: oauth1 -version: 1.0.5 +version: 1.0.6 description: "\"RFC 5849: The OAuth 1.0 Protocol\" client implementation for Dart." homepage: https://github.com/nbspou/dart-oauth1 author: kumar8600