From 4ebb63c5f719a28f38d7c54e72865170686d85ab Mon Sep 17 00:00:00 2001 From: "thomashii@dukefirehawk.com" Date: Sat, 3 Jun 2023 10:29:43 +0800 Subject: [PATCH] Fixed Auth failed test cases --- packages/auth/example/client/example1.http | 2 +- packages/auth/lib/src/strategies/local.dart | 8 ++++++++ packages/auth/test/local_test.dart | 1 + 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/auth/example/client/example1.http b/packages/auth/example/client/example1.http index 256c8ae2..7a5f2b73 100644 --- a/packages/auth/example/client/example1.http +++ b/packages/auth/example/client/example1.http @@ -12,6 +12,6 @@ Content-Type: application/json Authorization: Basic password:username ### Force basic -POST http://localhost:3000/hello HTTP/1.1 +GET http://localhost:3000/hello HTTP/1.1 Content-Type: application/json Accept:application/json \ No newline at end of file diff --git a/packages/auth/lib/src/strategies/local.dart b/packages/auth/lib/src/strategies/local.dart index b8e1b721..778f0842 100644 --- a/packages/auth/lib/src/strategies/local.dart +++ b/packages/auth/lib/src/strategies/local.dart @@ -71,6 +71,14 @@ class LocalAuthStrategy extends AuthStrategy { } } + if (verificationResult == null) { + if (forceBasic) { + res.headers['www-authenticate'] = 'Basic realm="$realm"'; + return null; + } + return null; + } + if (verificationResult is Map && verificationResult.isEmpty) { if (localOptions.failureRedirect != null && localOptions.failureRedirect!.isNotEmpty) { diff --git a/packages/auth/test/local_test.dart b/packages/auth/test/local_test.dart index 303e6d7b..07fab1f3 100644 --- a/packages/auth/test/local_test.dart +++ b/packages/auth/test/local_test.dart @@ -46,6 +46,7 @@ void main() async { app = Angel(reflector: MirrorsReflector()); angelHttp = AngelHttp(app, useZone: false); await app.configure(wireAuth); + app.get('/hello', (req, res) { // => 'Woo auth' return 'Woo auth';