dart2_constant

This commit is contained in:
Tobe O 2018-07-09 11:38:29 -04:00
parent 8e090e0c62
commit aca5489e8d
7 changed files with 24 additions and 18 deletions

View file

@ -3,6 +3,7 @@
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.dart_tool" />
<excludeFolder url="file://$MODULE_DIR$/.pub" />
<excludeFolder url="file://$MODULE_DIR$/build" />
</content>

3
CHANGELOG.md Normal file
View file

@ -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

View file

@ -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<Client, User> {
if (match != null) {
match = _rgxBasicAuth
.firstMatch(new String.fromCharCodes(BASE64URL.decode(match[1])));
.firstMatch(new String.fromCharCodes(base64Url.decode(match[1])));
}
if (match == null) {

View file

@ -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

View file

@ -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);

View file

@ -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',

View file

@ -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');
});