Patch basic auth

This commit is contained in:
Tobe O 2018-07-10 19:31:50 -04:00
parent e6403375b4
commit 18ebc9d554
4 changed files with 42 additions and 9 deletions

View file

@ -1,3 +1,8 @@
# 1.1.1+6
* Fix a small logic bug that prevented `LocalAuthStrategy`
from correctly propagating the authenticated user when
using `Basic` auth.
# 1.1.1+5
* Prevent duplication of cookies.
* Regenerate the JWT if `tokenCallback` is called.

View file

@ -61,13 +61,12 @@ class LocalAuthStrategy extends AuthStrategy {
if (verificationResult == false || verificationResult == null) {
res
..statusCode = 401
..headers[HttpHeaders.WWW_AUTHENTICATE] = 'Basic realm="$realm"'
..headers['www-authenticate'] = 'Basic realm="$realm"'
..end();
return false;
}
res.properties['user'] = verificationResult;
return true;
return verificationResult;
}
}
@ -75,8 +74,8 @@ class LocalAuthStrategy extends AuthStrategy {
await req.parse();
if (_validateString(req.body[usernameField]?.toString()) &&
_validateString(req.body[passwordField]?.toString())) {
verificationResult =
await verifier(req.body[usernameField]?.toString(), req.body[passwordField]?.toString());
verificationResult = await verifier(req.body[usernameField]?.toString(),
req.body[passwordField]?.toString());
}
}

View file

@ -1,6 +1,6 @@
name: angel_auth
description: A complete authentication plugin for Angel.
version: 1.1.1+5
version: 1.1.1+6
author: Tobe O <thosakwe@gmail.com>
homepage: https://github.com/angel-dart/angel_auth
environment:
@ -11,4 +11,6 @@ dependencies:
dart2_constant: ^1.0.0
dev_dependencies:
http: ^0.11.0
io: ^0.3.2
logging: ^0.11.0
test: ^0.12.0

View file

@ -4,6 +4,8 @@ import 'package:angel_framework/angel_framework.dart';
import 'package:angel_framework/common.dart';
import 'package:dart2_constant/convert.dart';
import 'package:http/http.dart' as http;
import 'package:io/ansi.dart';
import 'package:logging/logging.dart';
import 'package:test/test.dart';
class User extends Model {
@ -21,17 +23,39 @@ main() {
String url;
setUp(() async {
hierarchicalLoggingEnabled = true;
app = new Angel();
angelHttp = new AngelHttp(app, useZone: false);
angelHttp = new AngelHttp(app);
app.use('/users', new TypedService<User>(new MapService()));
var oldErrorHandler = app.errorHandler;
app.errorHandler = (e, req, res) {
app.logger.severe(e.message, e, e.stackTrace ?? StackTrace.current);
return oldErrorHandler(e, req, res);
};
app.logger = new Logger('angel_auth')
..level = Level.FINEST
..onRecord.listen((rec) {
print(rec);
if (rec.error != null) {
print(yellow.wrap(rec.error.toString()));
}
if (rec.stackTrace != null) {
print(yellow.wrap(rec.stackTrace.toString()));
}
});
await app
.service('users')
.create({'username': 'jdoe1', 'password': 'password'});
auth = new AngelAuth<User>();
auth.serializer = (u) => u.id;
auth.deserializer = app.service('users').read;
auth.deserializer =
(id) async => await app.service('users').read(id) as User;
await app.configure(auth.configureServer);
app.use(auth.decodeJwt);
@ -78,7 +102,10 @@ main() {
body: {'username': 'jdoe1', 'password': 'password'});
print('Response: ${response.body}');
expect(response.body, equals('Hello!'));
});
},
skip: Platform.version.contains('2.0.0-dev')
? 'Blocked on https://github.com/dart-lang/sdk/issues/33594'
: null);
test('preserve existing user', () async {
final response = await client.post('$url/existing/foo',