frontier_shelf 1.0.1 copy "frontier_shelf: ^1.0.1" to clipboard
frontier_shelf: ^1.0.1 copied to clipboard

A Shelf adapter for Frontier. It allows you to use Frontier with Shelf.

Frontier Banner

Frontier Shelf #

Frontier She is the strategy that provides email/password authentication for Frontier.

Get Started | Pub.dev

Installation #

Use the following to add the package to your pubspec.yaml file:

dart pub add frontier_shelf

Usage #

import 'package:frontier/frontier.dart';
import 'package:frontier_shelf/frontier_shelf.dart';
import 'package:shelf/shelf.dart';
import 'package:shelf/shelf_io.dart';

final class HeaderOptions extends StrategyOptions {
  final String key;
  final String value;

  HeaderOptions({required this.key, required this.value});
}

class HeaderStrategy extends Strategy<HeaderOptions> {
  HeaderStrategy(super.options, super.callback);

  @override
  String get name => 'Header';

  @override
  Future<void> authenticate(StrategyRequest request) async {
    final value = request.headers[options.key] == options.value;
    callback.call(options, value, done);
  }
}

void main(List<String> arguments) async {
  frontier.use(
      HeaderStrategy(HeaderOptions(key: 'hello', value: 'world'),
          (options, result, done) async {
    done(result);
  }));
  var handler = const Pipeline()
      .addMiddleware(frontierMiddleware(
          'Header', (req) async => StrategyRequest(headers: req.headers)))
      .addHandler((req) => Response.ok('ok!'));

  await serve(handler, '0.0.0.0', 3000);
}

License #

Frontier JWT is licensed under the MIT License.

1
likes
160
points
26
downloads

Publisher

verified publisherserinus.app

Weekly Downloads

A Shelf adapter for Frontier. It allows you to use Frontier with Shelf.

Homepage
Repository (GitHub)
View/report issues

Topics

#authentication #authorization #backend #shelf #http

Documentation

API reference

License

MIT (license)

Dependencies

frontier, shelf

More

Packages that depend on frontier_shelf