2024-10-13 01:45:27 +00:00
|
|
|
import 'package:protevus_auth/protevus_auth.dart';
|
|
|
|
import 'package:protevus_framework/protevus_framework.dart';
|
|
|
|
import 'package:protevus_framework/http.dart';
|
2023-06-07 16:42:34 +00:00
|
|
|
import 'package:logging/logging.dart';
|
|
|
|
|
|
|
|
void main() async {
|
|
|
|
const Map<String, String> user = {'username': 'foo', 'password': 'bar'};
|
|
|
|
var localOpts =
|
2024-10-13 02:17:24 +00:00
|
|
|
ProtevusAuthOptions<Map<String, String>>(canRespondWithJson: true);
|
2023-06-07 16:42:34 +00:00
|
|
|
|
2024-10-12 10:35:14 +00:00
|
|
|
Protevus app = Protevus();
|
|
|
|
ProtevusHttp http = ProtevusHttp(app, useZone: false);
|
2024-10-13 02:17:24 +00:00
|
|
|
var auth = ProtevusAuth(
|
2023-06-07 16:42:34 +00:00
|
|
|
serializer: (_) async => 'baz', deserializer: (_) async => user);
|
|
|
|
|
|
|
|
auth.strategies['local'] = LocalAuthStrategy((username, password) async {
|
|
|
|
if (username == 'foo' && password == 'bar') {
|
|
|
|
return user;
|
|
|
|
}
|
|
|
|
|
|
|
|
return {};
|
|
|
|
}, allowBasic: false);
|
|
|
|
|
|
|
|
app.post('/auth/local', auth.authenticate('local', localOpts));
|
|
|
|
|
|
|
|
await app.configure(auth.configureServer);
|
|
|
|
|
|
|
|
app.logger = Logger('auth_test')
|
|
|
|
..onRecord.listen((rec) {
|
|
|
|
print(
|
|
|
|
'${rec.time}: ${rec.level.name}: ${rec.loggerName}: ${rec.message}');
|
|
|
|
});
|
|
|
|
|
|
|
|
await http.startServer('127.0.0.1', 3000);
|
|
|
|
}
|