galileo_auth 3.0.1 copy "galileo_auth: ^3.0.1" to clipboard
galileo_auth: ^3.0.1 copied to clipboard

A complete authentication plugin for Galileo. Includes support for stateless JWT tokens, Basic Auth, and more.

example/example.dart

import 'dart:async';
import 'package:galileo_auth/galileo_auth.dart';
import 'package:galileo_framework/galileo_framework.dart';
import 'package:galileo_framework/http.dart';

main() async {
  var app = Galileo();
  var auth = GalileoAuth<User>();

  auth.serializer = (user) => user.id;

  auth.deserializer = (id) => fetchAUserByIdSomehow(id);

  // Middleware to decode JWT's and inject a user object...
  await app.configure(auth.configureServer);

  auth.strategies['local'] = LocalAuthStrategy((username, password) {
    // Retrieve a user somehow...
    // If authentication succeeds, return a User object.
    //
    // Otherwise, return `null`.
  });

  app.post('/auth/local', auth.authenticate('local'));

  var http = GalileoHttp(app);
  await http.startServer('127.0.0.1', 3000);

  print('Listening at http://127.0.0.1:3000');
}

class User {
  String id, username, password;
}

Future<User> fetchAUserByIdSomehow(id) async {
  // Fetch a user somehow...
  throw UnimplementedError();
}
1
likes
40
pub points
0%
popularity

Publisher

verified publishergalileodart.com

A complete authentication plugin for Galileo. Includes support for stateless JWT tokens, Basic Auth, and more.

Repository (GitHub)
View/report issues

License

MIT (LICENSE)

Dependencies

charcode, collection, crypto, galileo_framework, http_parser, meta, quiver

More

Packages that depend on galileo_auth