diff --git a/README.md b/README.md index 8e7ae431..f3cd0ea8 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ # auth_oauth2 -[![version 0.0.0](https://img.shields.io/badge/pub-v0.0.0-red.svg)](https://pub.dartlang.org/packages/angel_auth_oauth2) + +[![version 1.0.0](https://img.shields.io/badge/pub-1.0.0-brightgreen.svg)](https://pub.dartlang.org/packages/angel_auth_oauth2) angel_auth strategy for OAuth2 login, i.e. Facebook. diff --git a/example/basic.dart b/example/basic.dart index 00ca715d..cf3ed935 100644 --- a/example/basic.dart +++ b/example/basic.dart @@ -3,6 +3,7 @@ import 'dart:io'; import 'package:angel_auth/angel_auth.dart'; import 'package:angel_diagnostics/angel_diagnostics.dart'; import 'package:angel_framework/angel_framework.dart'; +import 'package:angel_framework/common.dart'; import 'package:angel_auth_oauth2/angel_auth_oauth2.dart'; import 'package:oauth2/oauth2.dart' as oauth2; @@ -15,7 +16,7 @@ const Map OAUTH2_CONFIG = const { }; main() async { - var app = new Angel()..use('/users', new MemoryService()); + var app = new Angel()..use('/users', new TypedService(new MapService())); var auth = new AngelAuth(jwtKey: 'oauth2 example secret', allowCookie: false); auth.deserializer = @@ -45,10 +46,10 @@ main() async { print('Listening on http://${server.address.address}:${server.port}'); } -class User extends MemoryModel { +class User extends Model { String example_siteId; - User({int id, this.example_siteId}) { + User({String id, this.example_siteId}) { this.id = id; } } diff --git a/lib/angel_auth_oauth2.dart b/lib/angel_auth_oauth2.dart index 6de6f066..0d29dfd2 100644 --- a/lib/angel_auth_oauth2.dart +++ b/lib/angel_auth_oauth2.dart @@ -8,7 +8,7 @@ import 'package:angel_validate/angel_validate.dart'; import 'package:oauth2/oauth2.dart' as oauth2; /// Loads a user profile via OAuth2. -typedef Future ProfileLoader(oauth2.Client client); +typedef Future OAuth2Verifier(oauth2.Client client); final Validator OAUTH2_OPTIONS_SCHEMA = new Validator({ 'key*': isString, @@ -23,11 +23,11 @@ final Validator OAUTH2_OPTIONS_SCHEMA = new Validator({ 'scopes': "'scopes' must be an Iterable of strings. You provided: {{value}}" }); -class AngelAuthOauth2Options { +class AngelAuthOAuth2Options { String key, secret, authorizationEndpoint, tokenEndpoint, callback; Iterable scopes; - AngelAuthOauth2Options( + AngelAuthOAuth2Options( {this.key, this.secret, this.authorizationEndpoint, @@ -37,8 +37,8 @@ class AngelAuthOauth2Options { this.scopes = scopes ?? []; } - factory AngelAuthOauth2Options.fromJson(Map json) => - new AngelAuthOauth2Options( + factory AngelAuthOAuth2Options.fromJson(Map json) => + new AngelAuthOAuth2Options( key: json['key'], secret: json['secret'], authorizationEndpoint: json['authorizationEndpoint'], @@ -60,8 +60,8 @@ class AngelAuthOauth2Options { class OAuth2Strategy implements AuthStrategy { String _name; - AngelAuthOauth2Options _options; - final ProfileLoader profileLoader; + AngelAuthOAuth2Options _options; + final OAuth2Verifier verifier; @override String get name => _name; @@ -69,12 +69,12 @@ class OAuth2Strategy implements AuthStrategy { @override set name(String value) => _name = name; - /// [options] can be either a `Map` or an instance of [AngelAuthOauth2Options]. - OAuth2Strategy(this._name, options, this.profileLoader) { - if (options is AngelAuthOauth2Options) + /// [options] can be either a `Map` or an instance of [AngelAuthOAuth2Options]. + OAuth2Strategy(this._name, options, this.verifier) { + if (options is AngelAuthOAuth2Options) _options = options; else if (options is Map) - _options = new AngelAuthOauth2Options.fromJson( + _options = new AngelAuthOAuth2Options.fromJson( OAUTH2_OPTIONS_SCHEMA.enforce(options)); else throw new ArgumentError('Invalid OAuth2 options: $options'); @@ -106,7 +106,7 @@ class OAuth2Strategy implements AuthStrategy { await grant.getAuthorizationUrl(Uri.parse(_options.callback), scopes: _options.scopes); var client = await grant.handleAuthorizationResponse(req.query); - return await profileLoader(client); + return await verifier(client); } @override diff --git a/pubspec.yaml b/pubspec.yaml index 3fb18d80..fcaae8ba 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: angel_auth_oauth2 description: angel_auth strategy for OAuth2 login, i.e. Facebook. -version: 0.0.0 +version: 1.0.0 author: Tobe O environment: sdk: ">=1.19.0"