From aca5489e8dd1a1ca8a37e57b46816799680691b6 Mon Sep 17 00:00:00 2001 From: Tobe O Date: Mon, 9 Jul 2018 11:38:29 -0400 Subject: [PATCH] dart2_constant --- .idea/auth_oauth2_server.iml | 1 + CHANGELOG.md | 3 +++ lib/src/server.dart | 4 ++-- pubspec.yaml | 3 ++- test/auth_code_test.dart | 17 +++++++++-------- test/client_credentials_test.dart | 11 +++++------ test/password_test.dart | 3 ++- 7 files changed, 24 insertions(+), 18 deletions(-) create mode 100644 CHANGELOG.md diff --git a/.idea/auth_oauth2_server.iml b/.idea/auth_oauth2_server.iml index 0fd729f3..ae9af975 100644 --- a/.idea/auth_oauth2_server.iml +++ b/.idea/auth_oauth2_server.iml @@ -3,6 +3,7 @@ + diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 00000000..2c05c775 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,3 @@ +# 1.0.1 +* Dart2 updates + backwards compatibility assurance. +* Added support for the `device_code` grant: https://github.com/angel-dart/oauth2/issues/7 \ No newline at end of file diff --git a/lib/src/server.dart b/lib/src/server.dart index 07ec42a5..489b5c65 100644 --- a/lib/src/server.dart +++ b/lib/src/server.dart @@ -1,6 +1,6 @@ import 'dart:async'; -import 'dart:convert'; import 'package:angel_framework/angel_framework.dart'; +import 'package:dart2_constant/convert.dart'; import 'exception.dart'; import 'response.dart'; import 'token_type.dart'; @@ -296,7 +296,7 @@ abstract class AuthorizationServer { if (match != null) { match = _rgxBasicAuth - .firstMatch(new String.fromCharCodes(BASE64URL.decode(match[1]))); + .firstMatch(new String.fromCharCodes(base64Url.decode(match[1]))); } if (match == null) { diff --git a/pubspec.yaml b/pubspec.yaml index 7863ab17..957c3ce5 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -4,9 +4,10 @@ description: angel_auth strategy for in-house OAuth2 login. homepage: https://github.com/angel-dart/oauth2.git version: 1.0.0 environment: - sdk: ">=1.19.0" + sdk: ">=1.8.0 <3.0.0" dependencies: angel_framework: ^1.0.0-dev + dart2_constant: ^1.0.0 dev_dependencies: angel_test: ^1.1.0-alpha oauth2: ^1.0.0 diff --git a/test/auth_code_test.dart b/test/auth_code_test.dart index c8cf64c0..bb82e4b7 100644 --- a/test/auth_code_test.dart +++ b/test/auth_code_test.dart @@ -1,8 +1,8 @@ import 'dart:async'; -import 'dart:convert'; import 'package:angel_framework/angel_framework.dart'; import 'package:angel_oauth2/angel_oauth2.dart'; import 'package:angel_test/angel_test.dart'; +import 'package:dart2_constant/convert.dart'; import 'package:logging/logging.dart'; import 'package:oauth2/oauth2.dart' as oauth2; import 'package:test/test.dart'; @@ -34,8 +34,9 @@ main() { if (rec.stackTrace != null) print(rec.stackTrace); }); - var http = await app.startServer(); - var url = 'http://${http.address.address}:${http.port}'; + var http = new AngelHttp(app); + var s = await http.startServer(); + var url = 'http://${s.address.address}:${s.port}'; authorizationEndpoint = Uri.parse('$url/oauth2/authorize'); tokenEndpoint = Uri.parse('$url/oauth2/token'); redirectUri = Uri.parse('http://foo.bar/baz'); @@ -63,7 +64,7 @@ main() { print('Body: ${response.body}'); expect( response.body, - JSON.encode( + json.encode( 'Hello ${pseudoApplication.id}:${pseudoApplication.secret}')); }); @@ -72,7 +73,7 @@ main() { var url = grant.getAuthorizationUrl(redirectUri, state: 'goodbye'); var response = await testClient.client.get(url); print('Body: ${response.body}'); - expect(JSON.decode(response.body)['state'], 'goodbye'); + expect(json.decode(response.body)['state'], 'goodbye'); }); test('sends auth code', () async { @@ -81,7 +82,7 @@ main() { var response = await testClient.client.get(url); print('Body: ${response.body}'); expect( - JSON.decode(response.body), + json.decode(response.body), allOf( isMap, predicate((Map m) => m.containsKey('code'), 'contains "code"'), @@ -95,7 +96,7 @@ main() { var response = await testClient.client.get(url); print('Body: ${response.body}'); - var authCode = JSON.decode(response.body)['code']; + var authCode = json.decode(response.body)['code']; var client = await grant.handleAuthorizationCode(authCode); expect(client.credentials.accessToken, authCode + '_access'); }); @@ -106,7 +107,7 @@ main() { var response = await testClient.client.get(url); print('Body: ${response.body}'); - var authCode = JSON.decode(response.body)['code']; + var authCode = json.decode(response.body)['code']; var client = await grant.handleAuthorizationCode(authCode); expect(client.credentials.accessToken, authCode + '_access'); expect(client.credentials.canRefresh, isTrue); diff --git a/test/client_credentials_test.dart b/test/client_credentials_test.dart index 22fa6042..b82a6445 100644 --- a/test/client_credentials_test.dart +++ b/test/client_credentials_test.dart @@ -1,10 +1,9 @@ import 'dart:async'; -import 'dart:convert'; -import 'dart:io'; import 'package:angel_framework/angel_framework.dart'; import 'package:angel_test/angel_test.dart'; import 'package:angel_oauth2/angel_oauth2.dart'; import 'package:angel_validate/angel_validate.dart'; +import 'package:dart2_constant/convert.dart'; import 'package:test/test.dart'; import 'common.dart'; @@ -34,7 +33,7 @@ main() { var response = await client.post( '/oauth2/token', headers: { - 'Authorization': 'Basic ' + BASE64URL.encode('foo:bar'.codeUnits), + 'Authorization': 'Basic ' + base64Url.encode('foo:bar'.codeUnits), }, body: { 'grant_type': 'client_credentials', @@ -45,7 +44,7 @@ main() { expect(response, allOf( hasStatus(200), - hasContentType(ContentType.JSON), + hasContentType('application/json'), hasValidBody(new Validator({ 'token_type': equals('bearer'), 'access_token': equals('foo'), @@ -57,7 +56,7 @@ main() { var response = await client.post( '/oauth2/token', headers: { - 'Authorization': 'Basic ' + BASE64URL.encode('fooa:bar'.codeUnits), + 'Authorization': 'Basic ' + base64Url.encode('fooa:bar'.codeUnits), }, body: { 'grant_type': 'client_credentials', @@ -72,7 +71,7 @@ main() { var response = await client.post( '/oauth2/token', headers: { - 'Authorization': 'Basic ' + BASE64URL.encode('foo:bara'.codeUnits), + 'Authorization': 'Basic ' + base64Url.encode('foo:bara'.codeUnits), }, body: { 'grant_type': 'client_credentials', diff --git a/test/password_test.dart b/test/password_test.dart index ba21f389..9baea1d5 100644 --- a/test/password_test.dart +++ b/test/password_test.dart @@ -26,7 +26,8 @@ main() { app.logger = new Logger('password_test')..onRecord.listen(print); - var server = await app.startServer(); + var http = new AngelHttp(app); + var server = await http.startServer(); var url = 'http://${server.address.address}:${server.port}'; tokenEndpoint = Uri.parse('$url/oauth2/token'); });