Updated auth

This commit is contained in:
thomashii@dukefirehawk.com 2021-05-29 09:48:33 +08:00
parent ef0e625707
commit e79826bad0
6 changed files with 28 additions and 19 deletions

View file

@ -12,7 +12,7 @@
* Added merge_map and migrated to 2.0.0 (6/6 tests passed) * Added merge_map and migrated to 2.0.0 (6/6 tests passed)
* Added mock_request and migrated to 2.0.0 (0/0 tests) * Added mock_request and migrated to 2.0.0 (0/0 tests)
* Migrated angel_framework to 4.0.0 (149/150 tests passed) * Migrated angel_framework to 4.0.0 (149/150 tests passed)
* Migrated angel_auth to 4.0.0 (23/30 tests passed) * Migrated angel_auth to 4.0.0 (25/30 tests passed)
* Migrated angel_configuration to 4.0.0 (6/8 testspassed) * Migrated angel_configuration to 4.0.0 (6/8 testspassed)
* Migrated angel_validate to 4.0.0 (6/7 tests passed) * Migrated angel_validate to 4.0.0 (6/7 tests passed)
* Migrated json_god to 4.0.0 (13/13 tests passed) * Migrated json_god to 4.0.0 (13/13 tests passed)
@ -40,6 +40,8 @@
* Migrated angel_orm_test to 3.0.0 (0/0 tests passed) * Migrated angel_orm_test to 3.0.0 (0/0 tests passed)
* Migrated angel_orm_postgres to 3.0.0 (51/54 tests passed) * Migrated angel_orm_postgres to 3.0.0 (51/54 tests passed)
* Create orm-sdk-2.12.x boilerplate (in progress) <= Milestone 2 * Create orm-sdk-2.12.x boilerplate (in progress) <= Milestone 2
* Migrate angel_cache
* Migrate angel_cors
# 3.0.0 (Non NNBD) # 3.0.0 (Non NNBD)
* Changed Dart SDK requirements for all packages to ">=2.10.0 <3.0.0" * Changed Dart SDK requirements for all packages to ">=2.10.0 <3.0.0"

View file

@ -1,3 +1,6 @@
# 4.0.2
* Added MirrorsReflector to test cases
# 4.0.1 # 4.0.1
* Updated README * Updated README

View file

@ -1,5 +1,5 @@
# angel3_auth # angel3_auth
[![version](https://img.shields.io/badge/pub-v4.0.1-brightgreen)](https://pub.dartlang.org/packages/angel3_auth) [![version](https://img.shields.io/badge/pub-v4.0.2-brightgreen)](https://pub.dartlang.org/packages/angel3_auth)
[![Null Safety](https://img.shields.io/badge/null-safety-brightgreen)](https://dart.dev/null-safety) [![Null Safety](https://img.shields.io/badge/null-safety-brightgreen)](https://dart.dev/null-safety)
[![Gitter](https://img.shields.io/gitter/room/angel_dart/discussion)](https://gitter.im/angel_dart/discussion) [![Gitter](https://img.shields.io/gitter/room/angel_dart/discussion)](https://gitter.im/angel_dart/discussion)

View file

@ -1,11 +1,13 @@
name: angel3_auth name: angel3_auth
description: A complete authentication plugin for Angel. Includes support for stateless JWT tokens, Basic Auth, and more. description: A complete authentication plugin for Angel. Includes support for stateless JWT tokens, Basic Auth, and more.
version: 4.0.1 version: 4.0.2
homepage: https://github.com/dukefirehawk/angel/tree/angel3/packages/auth homepage: https://github.com/dukefirehawk/angel/tree/angel3/packages/auth
publish_to: none
environment: environment:
sdk: '>=2.12.0 <3.0.0' sdk: '>=2.12.0 <3.0.0'
dependencies: dependencies:
angel3_framework: ^4.0.0 angel3_framework: #^4.0.0
path: ../framework
charcode: ^1.2.0 charcode: ^1.2.0
collection: ^1.15.0 collection: ^1.15.0
crypto: ^3.0.0 crypto: ^3.0.0
@ -13,6 +15,7 @@ dependencies:
meta: ^1.3.0 meta: ^1.3.0
quiver: ^3.0.0 quiver: ^3.0.0
dev_dependencies: dev_dependencies:
angel3_container: ^3.0.0
http: ^0.13.1 http: ^0.13.1
io: ^1.0.0 io: ^1.0.0
logging: ^1.0.0 logging: ^1.0.0

View file

@ -1,5 +1,6 @@
import 'dart:io'; import 'dart:io';
import 'package:angel3_auth/angel3_auth.dart'; import 'package:angel3_auth/angel3_auth.dart';
import 'package:angel3_container/mirrors.dart';
import 'package:angel3_framework/angel3_framework.dart'; import 'package:angel3_framework/angel3_framework.dart';
import 'package:angel3_framework/http.dart'; import 'package:angel3_framework/http.dart';
import 'dart:convert'; import 'dart:convert';
@ -36,14 +37,14 @@ class User extends Model {
void main() { void main() {
late Angel app; late Angel app;
late AngelHttp angelHttp; late AngelHttp angelHttp;
AngelAuth<User?> auth; AngelAuth<User> auth;
http.Client? client; http.Client? client;
HttpServer server; HttpServer server;
String? url; String? url;
setUp(() async { setUp(() async {
hierarchicalLoggingEnabled = true; hierarchicalLoggingEnabled = true;
app = Angel(); app = Angel(reflector: MirrorsReflector());
angelHttp = AngelHttp(app); angelHttp = AngelHttp(app);
app.use('/users', MapService()); app.use('/users', MapService());
@ -71,8 +72,8 @@ void main() {
.findService('users')! .findService('users')!
.create({'username': 'jdoe1', 'password': 'password'}); .create({'username': 'jdoe1', 'password': 'password'});
auth = AngelAuth<User?>(); auth = AngelAuth<User>();
auth.serializer = (u) => u!.id; auth.serializer = (u) => u.id;
auth.deserializer = auth.deserializer =
(id) async => await app.findService('users')!.read(id) as User; (id) async => await app.findService('users')!.read(id) as User;

View file

@ -32,7 +32,7 @@ Future wireAuth(Angel app) async {
void main() async { void main() async {
Angel app; Angel app;
late AngelHttp angelHttp; late AngelHttp angelHttp;
http.Client? client; late http.Client client;
String? url; String? url;
String? basicAuthUrl; String? basicAuthUrl;
@ -66,13 +66,13 @@ void main() async {
tearDown(() async { tearDown(() async {
await angelHttp.close(); await angelHttp.close();
client = null; //client = null;
url = null; url = null;
basicAuthUrl = null; basicAuthUrl = null;
}); });
test('can use "auth" as middleware', () async { test('can use "auth" as middleware', () async {
var response = await client!.get(Uri.parse('$url/success'), var response = await client.get(Uri.parse('$url/success'),
headers: {'Accept': 'application/json'}); headers: {'Accept': 'application/json'});
print(response.body); print(response.body);
expect(response.statusCode, equals(403)); expect(response.statusCode, equals(403));
@ -80,7 +80,7 @@ void main() async {
test('successRedirect', () async { test('successRedirect', () async {
var postData = {'username': 'username', 'password': 'password'}; var postData = {'username': 'username', 'password': 'password'};
var response = await client!.post(Uri.parse('$url/login'), var response = await client.post(Uri.parse('$url/login'),
body: json.encode(postData), body: json.encode(postData),
headers: {'content-type': 'application/json'}); headers: {'content-type': 'application/json'});
expect(response.statusCode, equals(302)); expect(response.statusCode, equals(302));
@ -89,7 +89,7 @@ void main() async {
test('failureRedirect', () async { test('failureRedirect', () async {
var postData = {'username': 'password', 'password': 'username'}; var postData = {'username': 'password', 'password': 'username'};
var response = await client!.post(Uri.parse('$url/login'), var response = await client.post(Uri.parse('$url/login'),
body: json.encode(postData), body: json.encode(postData),
headers: {'content-type': 'application/json'}); headers: {'content-type': 'application/json'});
print('Login response: ${response.body}'); print('Login response: ${response.body}');
@ -99,13 +99,13 @@ void main() async {
test('allow basic', () async { test('allow basic', () async {
var authString = base64.encode('username:password'.runes.toList()); var authString = base64.encode('username:password'.runes.toList());
var response = await client!.get(Uri.parse('$url/hello'), var response = await client.get(Uri.parse('$url/hello'),
headers: {'authorization': 'Basic $authString'}); headers: {'authorization': 'Basic $authString'});
expect(response.body, equals('"Woo auth"')); expect(response.body, equals('"Woo auth"'));
}); });
test('allow basic via URL encoding', () async { test('allow basic via URL encoding', () async {
var response = await client!.get(Uri.parse('$basicAuthUrl/hello')); var response = await client.get(Uri.parse('$basicAuthUrl/hello'));
expect(response.body, equals('"Woo auth"')); expect(response.body, equals('"Woo auth"'));
}); });
@ -113,13 +113,13 @@ void main() async {
auth.strategies.clear(); auth.strategies.clear();
auth.strategies['local'] = auth.strategies['local'] =
LocalAuthStrategy(verifier, forceBasic: true, realm: 'test'); LocalAuthStrategy(verifier, forceBasic: true, realm: 'test');
var response = await client?.get(Uri.parse('$url/hello'), headers: { var response = await client.get(Uri.parse('$url/hello'), headers: {
'accept': 'application/json', 'accept': 'application/json',
'content-type': 'application/json' 'content-type': 'application/json'
}); });
print('Header = ${response?.headers}'); print('Header = ${response.headers}');
print('Body <${response?.body}>'); print('Body <${response.body}>');
var head = response?.headers['www-authenticate']; var head = response.headers['www-authenticate'];
expect(head, equals('Basic realm="test"')); expect(head, equals('Basic realm="test"'));
}); });
} }