jaguar_auth_mongo 2.1.4

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 62

jaguar_auth_mongo

Jaguar AuthModelManager for MongoDb backend

Usage

User model that implements AuthorizationUser.

class User implements AuthorizationUser {
  String id;

  String username;

  String password;

  User();

  User.make(this.id, this.username, this.password);

  String get authorizationId => id;
}

Mongo model manager to fetch and authenticate the user model.

final MgoUserManager<User> modelManager =
    new MgoUserManager<User>(userMgoSerializer);

Interface containing all the MongoDb and Authorizer interceptor creators.

abstract class BaseApi {
  /// Interceptor creator for authorization
  Authorizer authorizer(Context ctx) => new Authorizer(modelManager);

  /// Interceptor creator to connect to MongoDb
  MongoDb mongoDb(Context ctx) => new MongoDb('mongodb://localhost:27017/test');
}

Authorization routes.

/// This route group contains login and logout routes
@Api(path: '/auth')
@WrapOne(#mongoDb)
class AuthRoutes extends BaseApi {
  @Post(path: '/login')
  Future login(Context ctx) async {
    await BasicAuth.authenticate(ctx, modelManager);
  }

  @Post(path: '/logout')
  Future logout(Context ctx) async {
    // Clear session
    (await ctx.session).clear();
  }
}

Authorized routes.

/// Collection of routes students can also access
@Api(path: '/book')
@Wrap(const [#mongoDb, #authorizer])
class StudentRoutes extends BaseApi {
  @Get(path: '/all')
  Response<String> getAllBooks(Context ctx) {
    List<Map> ret =
        _books.values.map((Book book) => bookSerializer.toMap(book)).toList();
    return Response.json(ret);
  }

  @Get(path: '/:id')
  Response<String> getBook(Context ctx) {
    final String id = ctx.pathParams.get('id');
    final Book book = _books[id];
    return Response.json(bookSerializer.toMap(book));
  }
}

Changelog

2.1.1

  • Architecture
  • Introducing MgoUserManager

example/example.dart

library example.basic_auth.server;

import 'dart:async';
import 'package:jaguar/jaguar.dart';
import 'package:jaguar_reflect/jaguar_reflect.dart';
import 'package:jaguar_auth/jaguar_auth.dart';
import 'package:jaguar_auth_mongo/jaguar_auth_mongo.dart';
import 'package:jaguar_mongo/jaguar_mongo.dart';

import 'model/model.dart';

final Map<String, Book> _books = {
  '0': new Book.make('0', 'Book0', 'Author0'),
  '1': new Book.make('1', 'Book1', 'Author1'),
  '2': new Book.make('2', 'Book2', 'Author2'),
};

// Mongo pool
final mongoPool = MongoPool('mongodb://localhost:27017/test');

/// Interceptor creator to connect to MongoDb
Future<void> mongoInterceptor(Context ctx) => mongoPool.injectInterceptor(ctx);

/// This route group contains login and logout routes
@Controller(path: '/auth')
@Intercept([mongoInterceptor])
class AuthRoutes {
  @Post(path: '/login')
  Future login(Context ctx) async {
    await BasicAuth.authenticate<User>(ctx);
  }

  @Post(path: '/logout')
  Future logout(Context ctx) async {
    await Authorizer.authorize<User>(ctx);
    // Clear session
    (await ctx.session).clear();
  }
}

/// Collection of routes students can also access
@Controller(path: '/book')
@Intercept([mongoInterceptor, Authorizer<User>()])
class StudentRoutes {
  @Get(path: '/all')
  Response<String> getAllBooks(Context ctx) {
    List<Map> ret =
        _books.values.map((Book book) => bookSerializer.toMap(book)).toList();
    return Response.json(ret);
  }
}

@Controller(path: '/api')
class LibraryApi {
  @IncludeHandler()
  final auth = AuthRoutes();

  @IncludeHandler()
  final student = StudentRoutes();
}

main() async {
  final server = new Jaguar(port: 10000);
  server.userFetchers[User] = MgoUserManager<User>(userMgoSerializer);
  server.add(reflect(LibraryApi()));
  server.log.onRecord.listen(print);
  await server.serve(logRequests: true);
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  jaguar_auth_mongo: ^2.1.4

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter packages get

Alternatively, your editor might support pub get or flutter packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:jaguar_auth_mongo/jaguar_auth_mongo.dart';
  
Version Uploaded Documentation Archive
2.1.4 Aug 8, 2018 Go to the documentation of jaguar_auth_mongo 2.1.4 Download jaguar_auth_mongo 2.1.4 archive
2.1.2 Jul 10, 2018 Go to the documentation of jaguar_auth_mongo 2.1.2 Download jaguar_auth_mongo 2.1.2 archive
2.1.1 Jul 10, 2018 Go to the documentation of jaguar_auth_mongo 2.1.1 Download jaguar_auth_mongo 2.1.1 archive
1.3.1 Feb 2, 2018 Go to the documentation of jaguar_auth_mongo 1.3.1 Download jaguar_auth_mongo 1.3.1 archive
1.2.6 Jan 13, 2018 Go to the documentation of jaguar_auth_mongo 1.2.6 Download jaguar_auth_mongo 1.2.6 archive
1.1.5 Jan 11, 2018 Go to the documentation of jaguar_auth_mongo 1.1.5 Download jaguar_auth_mongo 1.1.5 archive
0.2.0 Dec 28, 2017 Go to the documentation of jaguar_auth_mongo 0.2.0 Download jaguar_auth_mongo 0.2.0 archive
0.1.2 Jul 9, 2017 Go to the documentation of jaguar_auth_mongo 0.1.2 Download jaguar_auth_mongo 0.1.2 archive
0.1.0 Jul 3, 2017 Go to the documentation of jaguar_auth_mongo 0.1.0 Download jaguar_auth_mongo 0.1.0 archive
0.0.1 May 26, 2017 Go to the documentation of jaguar_auth_mongo 0.0.1 Download jaguar_auth_mongo 0.0.1 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
25
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
62
Learn more about scoring.

We analyzed this package on Aug 10, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0
  • pana: 0.11.8

Platforms

Detected platforms: Flutter, other

Primary library: package:jaguar_auth_mongo/jaguar_auth_mongo.dart with components: io.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
auth_header ^2.1.1 2.1.1
jaguar ^2.1.37 2.1.37
jaguar_auth ^2.1.2 2.1.12
jaguar_common ^2.1.1 2.1.4
jaguar_mongo ^2.1.1 2.1.4
jaguar_serializer ^2.2.0 2.2.0
mongo_dart ^0.3.2 0.3.3
Transitive dependencies
async 2.0.8
bson 0.3.2
charcode 1.1.2
collection 1.14.11
conn_pool 2.1.6
convert 2.0.2
crypto 2.0.6
fixnum 0.10.8
http_server 0.9.8
logging 0.11.3+2
mime 0.9.6+2
mongo_dart_query 0.3.2
more 1.10.1
path 1.6.2
pool 1.3.6
stack_trace 1.9.3
typed_data 1.1.6
uuid 1.0.3
Dev dependencies
build_runner ^0.10.0
jaguar_reflect ^2.1.6
jaguar_serializer_cli ^2.2.0
jaguar_serializer_mongo ^2.1.1
test ^1.3.0