shelf_auth_session 0.4.12

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

shelf_auth_session

Build Status Pub Version

Session support for shelf_auth

TODO: ideally this would be merged or at least share code with shelf_simple_session

Usage

Coming ...

Features and bugs

Please file feature requests and bugs at the issue tracker.

Changelog

0.4.11

  • updated crypto dependency with required code changes

0.4.10

  • upgrade shelf_auth dependency

0.4.0

  • upgrade option, shelf and shelf_auth versions

0.3.0

  • require shelf_auth 0.5.0

0.2.0

  • upgrade shelf_auth dependency

0.0.1

  • Initial version, created by Stagehand.

example/shelf_auth_session.dart

// Copyright (c) 2014, Anders Holmgren. All rights reserved. Use of this source code
// is governed by a BSD-style license that can be found in the LICENSE file.

library shelf_auth_session.example;

import 'dart:async';

import 'package:http_exception/http_exception.dart';
import 'package:logging/logging.dart';
import 'package:option/option.dart';
import 'package:shelf/shelf.dart';
import 'package:shelf/shelf_io.dart' as io;
import 'package:shelf_auth/shelf_auth.dart';
import 'package:shelf_auth_session/shelf_auth_session.dart';
import 'package:shelf_exception_handler/shelf_exception_handler.dart';
import 'package:uuid/uuid.dart';

void main() {
  Logger.root.level = Level.FINER;
  Logger.root.onRecord.listen((lr) {
    print('${lr.time} ${lr.level} ${lr.message}');
  });

  var authMiddleware = (builder()
          .authenticator(new RandomAuthenticator())
          .jwtSession('moi', 'ssh', testLookup)..allowHttp = true)
      .build();

  var handler = const Pipeline()
      .addMiddleware(logRequests())
      .addMiddleware(exceptionHandler())
      .addMiddleware(authMiddleware)
      .addMiddleware(sessionMiddleware(new InMemorySessionRepository()))
      .addHandler(_fooHandler);

  io.serve(handler, 'localhost', 8080).then((server) {
    print('Serving at http://${server.address.host}:${server.port}');
  });
}

Response _fooHandler(Request request) {
  final s = session(request).get();
  final currCount = s['count'];
  final count = currCount == null ? 0 : currCount + 1;
  s['count'] = count;
  return new Response.ok("I'm in with "
      "${authenticatedContext().map((ac) => ac.principal.name)}: "
      "count is $count\n");
}

class RandomAuthenticator extends Authenticator {
  bool approve = true;
  bool readsBody = false;

  @override
  Future<Option<AuthenticatedContext>> authenticate(Request request) async {
    approve = !approve;
    final now = new DateTime.now();

    if (approve) {
      return new Some(new SessionAuthenticatedContext(new Principal("fred"),
          new Uuid().v4(), now, now, now.add(const Duration(days: 10))));
    } else {
      throw new UnauthorizedException();
    }
  }
}

Future<Option<Principal>> testLookup(String username) {
  return new Future.value(new Some(new Principal(username)));
}

Use this package as a library

1. Depend on it

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


dependencies:
  shelf_auth_session: ^0.4.12

2. Install it

You can install packages from the command line:

with pub:


$ pub get

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

3. Import it

Now in your Dart code, you can use:


import 'package:shelf_auth_session/shelf_auth_session.dart';
  
Version Uploaded Documentation Archive
0.4.12 Oct 21, 2016 Go to the documentation of shelf_auth_session 0.4.12 Download shelf_auth_session 0.4.12 archive
0.4.11 Apr 10, 2016 Go to the documentation of shelf_auth_session 0.4.11 Download shelf_auth_session 0.4.11 archive
0.4.10 Jan 6, 2016 Go to the documentation of shelf_auth_session 0.4.10 Download shelf_auth_session 0.4.10 archive
0.4.9 Aug 12, 2015 Go to the documentation of shelf_auth_session 0.4.9 Download shelf_auth_session 0.4.9 archive
0.4.8 Jul 14, 2015 Go to the documentation of shelf_auth_session 0.4.8 Download shelf_auth_session 0.4.8 archive
0.4.7 Jul 12, 2015 Go to the documentation of shelf_auth_session 0.4.7 Download shelf_auth_session 0.4.7 archive
0.4.6 Jul 4, 2015 Go to the documentation of shelf_auth_session 0.4.6 Download shelf_auth_session 0.4.6 archive
0.4.5 Jul 1, 2015 Go to the documentation of shelf_auth_session 0.4.5 Download shelf_auth_session 0.4.5 archive
0.4.4 Jun 25, 2015 Go to the documentation of shelf_auth_session 0.4.4 Download shelf_auth_session 0.4.4 archive
0.4.3 Jun 25, 2015 Go to the documentation of shelf_auth_session 0.4.3 Download shelf_auth_session 0.4.3 archive

All 17 versions...

Popularity:
Describes how popular the package is relative to other packages. [more]
0
Health:
Code health derived from static analysis. [more]
0
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
0
Overall:
Weighted score of the above. [more]
0
Learn more about scoring.

The package version is not analyzed, because it does not support Dart 2. Until this is resolved, the package will receive a health and maintenance score of 0.

Analysis issues and suggestions

Support Dart 2 in pubspec.yaml.

The SDK constraint in pubspec.yaml doesn't allow the Dart 2.0.0 release. For information about upgrading it to be Dart 2 compatible, please see https://www.dartlang.org/dart-2#migration.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.9.0 <2.0.0