2.0.3
This commit is contained in:
parent
e490afe637
commit
8e9c85cb96
7 changed files with 31 additions and 10 deletions
|
@ -1,3 +1,6 @@
|
|||
# 2.0.3
|
||||
* Updates for streaming parse of request bodies.
|
||||
|
||||
# 2.0.2
|
||||
* Handle `null` return in `authenticate` + `failureRedirect`.
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -205,7 +205,7 @@ class AngelAuth<User> {
|
|||
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) {
|
||||
|
|
|
@ -64,7 +64,10 @@ class LocalAuthStrategy<User> extends AuthStrategy<User> {
|
|||
}
|
||||
|
||||
if (verificationResult == null) {
|
||||
var body = await req.parseBody();
|
||||
var body = await req
|
||||
.parseBody()
|
||||
.then((_) => req.bodyAsMap)
|
||||
.catchError((_) => <String, dynamic>{});
|
||||
if (_validateString(body[usernameField]?.toString()) &&
|
||||
_validateString(body[passwordField]?.toString())) {
|
||||
verificationResult = await verifier(
|
||||
|
|
|
@ -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 <thosakwe@gmail.com>
|
||||
homepage: https://github.com/angel-dart/angel_auth
|
||||
environment:
|
||||
|
|
|
@ -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<User>();
|
||||
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>(User.parse).toList())) as Iterable<User>;
|
||||
.then((it) => it.map<User>((m) => User.parse(m as Map)).toList());
|
||||
return users.firstWhere(
|
||||
(user) => user.username == username && user.password == password,
|
||||
orElse: () => null);
|
||||
|
|
|
@ -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<Map<String, String>> 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"'));
|
||||
|
|
Loading…
Reference in a new issue