From 8e9c85cb96922cc5a5938f65e06f28a690a33d76 Mon Sep 17 00:00:00 2001 From: Tobe O Date: Sun, 9 Dec 2018 11:29:15 -0500 Subject: [PATCH] 2.0.3 --- CHANGELOG.md | 3 +++ example/example.dart | 1 + lib/src/plugin.dart | 2 +- lib/src/strategies/local.dart | 5 ++++- pubspec.yaml | 2 +- test/callback_test.dart | 11 ++++++----- test/local_test.dart | 17 +++++++++++++++-- 7 files changed, 31 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d2989422..359c5b68 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +# 2.0.3 +* Updates for streaming parse of request bodies. + # 2.0.2 * Handle `null` return in `authenticate` + `failureRedirect`. diff --git a/example/example.dart b/example/example.dart index 722cf066..916dd828 100644 --- a/example/example.dart +++ b/example/example.dart @@ -1,6 +1,7 @@ import 'dart:async'; import 'package:angel_auth/angel_auth.dart'; import 'package:angel_framework/angel_framework.dart'; +import 'package:angel_framework/http.dart'; main() async { var app = new Angel(); diff --git a/lib/src/plugin.dart b/lib/src/plugin.dart index 1236d075..352cf82d 100644 --- a/lib/src/plugin.dart +++ b/lib/src/plugin.dart @@ -205,7 +205,7 @@ class AngelAuth { var jwt = getJwt(req); if (jwt == null) { - var body = await req.parseBody(); + var body = await req.parseBody().then((_) => req.bodyAsMap); jwt = body['token']?.toString(); } if (jwt == null) { diff --git a/lib/src/strategies/local.dart b/lib/src/strategies/local.dart index 5007e4a9..fa6472b6 100644 --- a/lib/src/strategies/local.dart +++ b/lib/src/strategies/local.dart @@ -64,7 +64,10 @@ class LocalAuthStrategy extends AuthStrategy { } if (verificationResult == null) { - var body = await req.parseBody(); + var body = await req + .parseBody() + .then((_) => req.bodyAsMap) + .catchError((_) => {}); if (_validateString(body[usernameField]?.toString()) && _validateString(body[passwordField]?.toString())) { verificationResult = await verifier( diff --git a/pubspec.yaml b/pubspec.yaml index 240d08e5..cd82e309 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: angel_auth description: A complete authentication plugin for Angel. Includes support for stateless JWT tokens, Basic Auth, and more. -version: 2.0.2 +version: 2.0.3 author: Tobe O homepage: https://github.com/angel-dart/angel_auth environment: diff --git a/test/callback_test.dart b/test/callback_test.dart index c48dfb01..576d6cf0 100644 --- a/test/callback_test.dart +++ b/test/callback_test.dart @@ -1,6 +1,7 @@ import 'dart:io'; import 'package:angel_auth/angel_auth.dart'; import 'package:angel_framework/angel_framework.dart'; +import 'package:angel_framework/http.dart'; import 'dart:convert'; import 'package:http/http.dart' as http; import 'package:io/ansi.dart'; @@ -65,23 +66,23 @@ main() { }); await app - .service('users') + .findService('users') .create({'username': 'jdoe1', 'password': 'password'}); auth = new AngelAuth(); auth.serializer = (u) => u.id; auth.deserializer = - (id) async => await app.service('users').read(id) as User; + (id) async => await app.findService('users').read(id) as User; await app.configure(auth.configureServer); app.fallback(auth.decodeJwt); auth.strategies['local'] = new LocalAuthStrategy((username, password) async { - var users = (await app - .service('users') + var users = await app + .findService('users') .index() - .then((it) => it.map(User.parse).toList())) as Iterable; + .then((it) => it.map((m) => User.parse(m as Map)).toList()); return users.firstWhere( (user) => user.username == username && user.password == password, orElse: () => null); diff --git a/test/local_test.dart b/test/local_test.dart index 112d6311..c4985be0 100644 --- a/test/local_test.dart +++ b/test/local_test.dart @@ -1,9 +1,11 @@ import 'dart:async'; import 'dart:io'; -import 'package:angel_framework/angel_framework.dart'; import 'package:angel_auth/angel_auth.dart'; +import 'package:angel_framework/angel_framework.dart'; +import 'package:angel_framework/http.dart'; import 'dart:convert'; import 'package:http/http.dart' as http; +import 'package:logging/logging.dart'; import 'package:test/test.dart'; final AngelAuth> auth = @@ -50,6 +52,14 @@ main() async { ]); app.get('/failure', (req, res) => "nope"); + app.logger = new Logger('angel_auth') + ..onRecord.listen((rec) { + if (rec.error != null) { + print(rec.error); + print(rec.stackTrace); + } + }); + HttpServer server = await angelHttp.startServer('127.0.0.1', 0); url = "http://${server.address.host}:${server.port}"; basicAuthUrl = @@ -105,7 +115,10 @@ main() async { auth.strategies.clear(); auth.strategies['local'] = new LocalAuthStrategy(verifier, forceBasic: true, realm: 'test'); - var response = await client.get("$url/hello", headers: headers); + var response = await client.get("$url/hello", headers: { + 'accept': 'application/json', + 'content-type': 'application/json' + }); print(response.headers); print('Body <${response.body}>'); expect(response.headers['www-authenticate'], equals('Basic realm="test"'));