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

Basic authentication and authorization strategies for the Frontier package.

Frontier Banner

Frontier Basic #

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

Get Started | Pub.dev

Why Frontier Basic? #

Frontier Basic is a simple strategy that provides email/password authentication. It is designed to be easy to use and to integrate with your app.

Installation #

Add the following to your pubspec.yaml file:

dart pub add frontier_basic

Usage #

import 'dart:io';

import 'package:frontier/frontier.dart';
import 'package:frontier_basic/frontier_basic.dart';

void main() {
  final frontier = Frontier();

  frontier.use(
    BasicAuthStrategy(
      BasicAuthOptions(
        header: 'Authorization',
      ),
      (options, credentials, done) async {
        done(credentials == Credentials(username: 'admin', password: 'admin'));
      },
    )
  );

  final server = HttpServer.bind(InternetAddress.loopbackIPv4, 8080);

  server.then((server) {
    server.listen((HttpRequest request) async {
      final headers = <String, String>{};
      request.headers.forEach((key, values) {
        headers[key] = values.join(',');
      });
      final result = await frontier.authenticate(
        'BasicAuthentication',
        StrategyRequest(headers: headers),
      );
      if (result) {
        request.response.write('Authenticated');
      } else {
        request.response.statusCode = HttpStatus.unauthorized;
        request.response.write('Not Authenticated');
      }
    });
  });
}

License #

Frontier Basic is released under the MIT License. See LICENSE

1
likes
160
points
24
downloads

Publisher

verified publisherserinus.app

Weekly Downloads

Basic authentication and authorization strategies for the Frontier package.

Homepage
Repository (GitHub)

Topics

#authentication #authorization #backend #basic #http

Documentation

API reference

License

MIT (license)

Dependencies

frontier_strategy

More

Packages that depend on frontier_basic