jaguar_auth_mongo 2.4.1

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

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 'package:jaguar_example_session_models/jaguar_example_session_models.dart';
import 'model/model.dart';

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

/// This route group contains login and logout routes
@GenController(path: '/auth')
class AuthRoutes extends Controller {
  @Post(path: '/login')
  Future<String> login(Context ctx) async {
    await BasicAuth.authenticate<User>(ctx);
    return "Success";
  }

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

  @override
  Future<void> before(Context ctx) async {
    await mongoPool(ctx);
  }
}

/// Collection of routes students can also access
@GenController(path: '/books')
class StudentRoutes extends Controller {
  @GetJson()
  List<Book> getAllBooks(Context ctx) => books.values.toList();

  @override
  Future<void> before(Context ctx) async {
    await mongoPool(ctx);
    await Authorizer.authorize<User>(ctx);
  }
}

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

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

main() async {
  final server = 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.4.1

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.4.1 Sep 18, 2018 Go to the documentation of jaguar_auth_mongo 2.4.1 Download jaguar_auth_mongo 2.4.1 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

All 11 versions...

Popularity:
Describes how popular the package is relative to other packages. [more]
0
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]
50
Learn more about scoring.

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

  • Dart: 2.1.0
  • pana: 0.12.7

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.2
jaguar ^2.4.4 2.4.12
jaguar_auth ^2.4.1 2.4.1
jaguar_common ^2.1.1 2.1.4
jaguar_mongo ^2.4.1 2.4.1
jaguar_serializer ^2.2.0 2.2.5
mongo_dart ^0.3.3 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.8
convert 2.0.2
crypto 2.0.6
fixnum 0.10.9
http_server 0.9.8+1
logging 0.11.3+2
mime 0.9.6+2
mongo_dart_query 0.3.2
more 1.12.1
path 1.6.2
path_tree 2.2.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_client ^2.4.1
jaguar_example_session_models ^2.1.6
jaguar_reflect ^2.4.0
jaguar_resty ^2.8.0
jaguar_serializer_cli ^2.2.0
jaguar_serializer_mongo ^2.1.1
test ^1.3.0