shelf_auth_session 0.4.12

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

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)));
}

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...

Analysis

This feature is new.
We welcome feedback.

We analyzed this package, and provided a score, details, and suggestions below.

  • tool failures on Dec 6, 2017
  • Dart: 2.0.0-dev.8.0
  • pana: 0.7.3+1

Scores

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

Platforms

Detected platforms:

Error(s) prevent platform classification.

Suggestions

  • Fix lib/src/json_sha1_hash.dart.

    Strong-mode analysis of lib/src/json_sha1_hash.dart failed with the following error:

    line: 12 col: 21
    Undefined name 'sha1'.

Dependencies

Package Constraint Resolved Available
Direct dependencies
collection >=0.9.4 <2.0.0 1.14.3
http_exception ^0.1.0 0.1.0
option ^1.1.0 1.2.0
shelf ^0.6.0 0.6.8 0.7.1
shelf_auth ^0.7.4 0.7.4
Transitive dependencies
async 1.13.3 2.0.1
bignum 0.0.7 0.1.0
charcode 1.1.1
cipher 0.7.1
concepts 0.2.0
convert 2.0.1
crypto 2.0.2+1
dart_jwt 0.5.2 0.6.0
either 0.1.8
fixnum 0.9.1+2 0.10.6
http_parser 3.1.1
logging 0.11.3+1
matcher 0.12.1+4
path 1.5.1
shelf_path 0.1.8
source_span 1.4.0
stack_trace 1.9.1
stream_channel 1.6.2
string_scanner 1.0.2
typed_data 1.1.5
uuid 0.5.3
Dev dependencies
shelf_exception_handler ^0.1.0
test ^0.12.0