diff --git a/packages/auth/example/client/example_client.http b/packages/auth/example/client/example_client.http index 7a5f2b73..330cae03 100644 --- a/packages/auth/example/client/example_client.http +++ b/packages/auth/example/client/example_client.http @@ -1,12 +1,17 @@ ### Load landing page GET http://localhost:3000/ HTTP/1.1 -### Success redirect +### login (call_back) POST http://localhost:3000/login HTTP/1.1 Content-Type: application/json Authorization: Basic jdoe1:password -### Failure redirect +### Success redirect (local) +POST http://localhost:3000/login HTTP/1.1 +Content-Type: application/json +Authorization: Basic username:password + +### Failure redirect (local) POST http://localhost:3000/login HTTP/1.1 Content-Type: application/json Authorization: Basic password:username diff --git a/packages/auth/example/example2.dart b/packages/auth/example/example2.dart index 12210e64..77830377 100644 --- a/packages/auth/example/example2.dart +++ b/packages/auth/example/example2.dart @@ -25,10 +25,14 @@ Future> verifier(String? username, String? password) async { Future wireAuth(Angel app) async { //auth.strategies['local'] = LocalAuthStrategy(verifier); - auth.strategies['local'] = LocalAuthStrategy(verifier, forceBasic: true, realm: 'test'); + auth.strategies['local'] = + LocalAuthStrategy(verifier, forceBasic: true, realm: 'test'); await app.configure(auth.configureServer); } +/* + * Backend for local test cases + */ void main() async { Angel app = Angel(reflector: MirrorsReflector()); AngelHttp angelHttp = AngelHttp(app, useZone: false); diff --git a/packages/auth/lib/src/strategies/local.dart b/packages/auth/lib/src/strategies/local.dart index d2d58739..b89d2b6f 100644 --- a/packages/auth/lib/src/strategies/local.dart +++ b/packages/auth/lib/src/strategies/local.dart @@ -81,15 +81,22 @@ class LocalAuthStrategy extends AuthStrategy { } } - // User authentication succeeded - if (verificationResult == true || - (verificationResult is Map && verificationResult.isNotEmpty)) { - return verificationResult; + // User authentication succeeded can return Map(one element), User(non null) or true + if (verificationResult != null && verificationResult != false) { + if (verificationResult is Map && verificationResult.isNotEmpty) { + return verificationResult; + } else if (verificationResult is! Map) { + return verificationResult; + } } // Force basic if set if (forceBasic) { - res.headers['www-authenticate'] = 'Basic realm="$realm"'; + //res.headers['www-authenticate'] = 'Basic realm="$realm"'; + res + ..statusCode = 401 + ..headers['www-authenticate'] = 'Basic realm="$realm"'; + await res.close(); return null; }