diff --git a/CHANGELOG.md b/CHANGELOG.md index e80632d7..2d7a7ed3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,8 @@ -# 2.0.0-beta +# 2.0.0 * Made `AuthStrategy` generic. * `AngelAuth.strategies` is now a `Map>`. * Removed `AuthStrategy.canLogout`. +* Made `AngelAuthTokenCallback` generic. # 2.0.0-alpha * Depend on Dart 2 and Angel 2. diff --git a/lib/angel_auth.dart b/lib/angel_auth.dart index bd2e0a8e..a27a64d5 100644 --- a/lib/angel_auth.dart +++ b/lib/angel_auth.dart @@ -3,7 +3,6 @@ library angel_auth; export 'src/middleware/require_auth.dart'; export 'src/strategies/strategies.dart'; export 'src/auth_token.dart'; -export 'src/defs.dart'; export 'src/options.dart'; export 'src/plugin.dart'; export 'src/popup_page.dart'; diff --git a/lib/src/defs.dart b/lib/src/defs.dart deleted file mode 100644 index c7538c9e..00000000 --- a/lib/src/defs.dart +++ /dev/null @@ -1,7 +0,0 @@ -import 'dart:async'; - -/// Serializes a user to the session. -typedef FutureOr UserSerializer(T user); - -/// Deserializes a user from the session. -typedef FutureOr UserDeserializer(userId); diff --git a/lib/src/options.dart b/lib/src/options.dart index b2dd08f0..2f469fde 100644 --- a/lib/src/options.dart +++ b/lib/src/options.dart @@ -1,15 +1,17 @@ +import 'dart:async'; + import 'package:angel_framework/angel_framework.dart'; import 'auth_token.dart'; -typedef AngelAuthCallback( +typedef FutureOr AngelAuthCallback( RequestContext req, ResponseContext res, String token); -typedef AngelAuthTokenCallback( - RequestContext req, ResponseContext res, AuthToken token, user); +typedef FutureOr AngelAuthTokenCallback( + RequestContext req, ResponseContext res, AuthToken token, User user); -class AngelAuthOptions { +class AngelAuthOptions { AngelAuthCallback callback; - AngelAuthTokenCallback tokenCallback; + AngelAuthTokenCallback tokenCallback; String successRedirect; String failureRedirect; diff --git a/lib/src/plugin.dart b/lib/src/plugin.dart index 26ede098..a1ff1cf0 100644 --- a/lib/src/plugin.dart +++ b/lib/src/plugin.dart @@ -4,7 +4,6 @@ import 'dart:math' as Math; import 'package:angel_framework/angel_framework.dart'; import 'package:crypto/crypto.dart'; import 'auth_token.dart'; -import 'defs.dart'; import 'options.dart'; import 'strategy.dart'; @@ -49,10 +48,10 @@ class AngelAuth { Map> strategies = {}; /// Serializes a user into a unique identifier associated only with one identity. - UserSerializer serializer; + FutureOr Function(User) serializer; /// Deserializes a unique identifier into its associated identity. In most cases, this is a user object or model instance. - UserDeserializer deserializer; + FutureOr Function(Object) deserializer; /// Fires the result of [deserializer] whenever a user signs in to the application. Stream get onLogin => _onLogin.stream; @@ -75,6 +74,8 @@ class AngelAuth { /// `jwtLifeSpan` - should be in *milliseconds*. AngelAuth( {String jwtKey, + this.serializer, + this.deserializer, num jwtLifeSpan, this.allowCookie: true, this.allowTokenInQuery: true, @@ -250,7 +251,7 @@ class AngelAuth { /// or a `401 Not Authenticated` is thrown, if it is the last one. /// /// Any other result is considered an authenticated user, and terminates the loop. - RequestHandler authenticate(type, [AngelAuthOptions options]) { + RequestHandler authenticate(type, [AngelAuthOptions options]) { return (RequestContext req, ResponseContext res) async { List names = []; var arr = type is Iterable ? type.toList() : [type]; @@ -356,7 +357,7 @@ class AngelAuth { } /// Log an authenticated user out. - RequestHandler logout([AngelAuthOptions options]) { + RequestHandler logout([AngelAuthOptions options]) { return (RequestContext req, ResponseContext res) async { if (req.container.has()) { var user = req.container.make(); diff --git a/pubspec.yaml b/pubspec.yaml index b2f9587f..1c861022 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: angel_auth description: A complete authentication plugin for Angel. -version: 2.0.0-beta +version: 2.0.0 author: Tobe O homepage: https://github.com/angel-dart/angel_auth environment: diff --git a/test/local_test.dart b/test/local_test.dart index 6f0a34b1..f95202be 100644 --- a/test/local_test.dart +++ b/test/local_test.dart @@ -9,7 +9,7 @@ import 'package:test/test.dart'; final AngelAuth> auth = new AngelAuth>(); var headers = {'accept': 'application/json'}; -AngelAuthOptions localOpts = new AngelAuthOptions( +var localOpts = new AngelAuthOptions>( failureRedirect: '/failure', successRedirect: '/success'); Map sampleUser = {'hello': 'world'};