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 # 1.1.1+5
* Prevent duplication of cookies. * Prevent duplication of cookies.
* Regenerate the JWT if `tokenCallback` is called. * Regenerate the JWT if `tokenCallback` is called.

View file

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

View file

@ -1,6 +1,6 @@
name: angel_auth name: angel_auth
description: A complete authentication plugin for Angel. description: A complete authentication plugin for Angel.
version: 1.1.1+5 version: 1.1.1+6
author: Tobe O <thosakwe@gmail.com> author: Tobe O <thosakwe@gmail.com>
homepage: https://github.com/angel-dart/angel_auth homepage: https://github.com/angel-dart/angel_auth
environment: environment:
@ -11,4 +11,6 @@ dependencies:
dart2_constant: ^1.0.0 dart2_constant: ^1.0.0
dev_dependencies: dev_dependencies:
http: ^0.11.0 http: ^0.11.0
io: ^0.3.2
logging: ^0.11.0
test: ^0.12.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:angel_framework/common.dart';
import 'package:dart2_constant/convert.dart'; import 'package:dart2_constant/convert.dart';
import 'package:http/http.dart' as http; import 'package:http/http.dart' as http;
import 'package:io/ansi.dart';
import 'package:logging/logging.dart';
import 'package:test/test.dart'; import 'package:test/test.dart';
class User extends Model { class User extends Model {
@ -21,17 +23,39 @@ main() {
String url; String url;
setUp(() async { setUp(() async {
hierarchicalLoggingEnabled = true;
app = new Angel(); app = new Angel();
angelHttp = new AngelHttp(app, useZone: false); angelHttp = new AngelHttp(app);
app.use('/users', new TypedService<User>(new MapService())); 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 await app
.service('users') .service('users')
.create({'username': 'jdoe1', 'password': 'password'}); .create({'username': 'jdoe1', 'password': 'password'});
auth = new AngelAuth<User>(); auth = new AngelAuth<User>();
auth.serializer = (u) => u.id; 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); await app.configure(auth.configureServer);
app.use(auth.decodeJwt); app.use(auth.decodeJwt);
@ -78,7 +102,10 @@ main() {
body: {'username': 'jdoe1', 'password': 'password'}); body: {'username': 'jdoe1', 'password': 'password'});
print('Response: ${response.body}'); print('Response: ${response.body}');
expect(response.body, equals('Hello!')); 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 { test('preserve existing user', () async {
final response = await client.post('$url/existing/foo', final response = await client.post('$url/existing/foo',