shelf_auth_session 0.4.12

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

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

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

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

  • Dart: 2.0.0-dev.63.0
  • pana: 0.11.3

Scores

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

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in primary library package:shelf_auth_session/shelf_auth_session.dart.

Suggestions

  • Fix analysis and formatting issues.

    Analysis or formatting checks reported 3 errors 3 hints.

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

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

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

    line: 47 col: 60
    The argument type '(Response) → Future<Response>' can't be assigned to the parameter type '(dynamic) → FutureOr<dynamic>'.

  • Package is getting outdated.

    The package was released 86 weeks ago.

  • The description is too short.

    Add more detail about the package, what it does and what is its target use case. Try to write at least 60 characters.

  • Package is pre-v1 release.

    While there is nothing inherently wrong with versions of 0.*.*, it usually means that the author is still experimenting with the general direction API.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.9.0 <2.0.0
collection >=0.9.4 <2.0.0 1.14.10
http_exception ^0.1.0 0.1.0
option ^1.1.0 1.2.0
shelf ^0.6.0 0.6.8 0.7.3+1
shelf_auth ^0.7.4 0.7.4
Transitive dependencies
async 1.13.3 2.0.7
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.5
dart_jwt 0.5.2 0.6.0
either 0.1.8
fixnum 0.9.1+2 0.10.7
http_parser 3.1.2
logging 0.11.3+1
matcher 0.12.3
path 1.6.1
shelf_path 0.1.8
source_span 1.4.0
stack_trace 1.9.2
stream_channel 1.6.7+1
string_scanner 1.0.2
typed_data 1.1.5
uuid 0.5.3 1.0.0
Dev dependencies
shelf_exception_handler ^0.1.0
test ^0.12.0