import 'dart:async'; import 'package:protevus_auth/protevus_auth.dart'; import 'package:protevus_container/mirrors.dart'; import 'package:protevus_framework/protevus_framework.dart'; import 'package:protevus_framework/http.dart'; import 'package:logging/logging.dart'; final Map sampleUser = {'hello': 'world'}; final AngelAuth> auth = AngelAuth>( serializer: (user) async => '1337', deserializer: (id) async => sampleUser); //var headers = {'accept': 'application/json'}; var localOpts = AngelAuthOptions>( failureRedirect: '/failure', successRedirect: '/success'); var localOpts2 = AngelAuthOptions>(canRespondWithJson: false); Future> verifier(String? username, String? password) async { if (username == 'username' && password == 'password') { return sampleUser; } else { return {}; } } Future wireAuth(Protevus app) async { //auth.strategies['local'] = LocalAuthStrategy(verifier); auth.strategies['local'] = LocalAuthStrategy(verifier, forceBasic: true, realm: 'test'); await app.configure(auth.configureServer); } /* * Backend for local test cases */ void main() async { Protevus app = Protevus(reflector: MirrorsReflector()); ProtevusHttp angelHttp = ProtevusHttp(app, useZone: false); await app.configure(wireAuth); app.get('/hello', (req, res) { // => 'Woo auth' return 'Woo auth'; }, middleware: [auth.authenticate('local', localOpts2)]); app.post('/login', (req, res) => 'This should not be shown', middleware: [auth.authenticate('local', localOpts)]); app.get('/success', (req, res) => 'yep', middleware: [ requireAuthentication>(), ]); app.get('/failure', (req, res) => 'nope'); app.logger = Logger('local_test') ..onRecord.listen((rec) { print( '${rec.time}: ${rec.level.name}: ${rec.loggerName}: ${rec.message}'); if (rec.error != null) { print(rec.error); print(rec.stackTrace); } }); await angelHttp.startServer('127.0.0.1', 3000); }