Merge pull request #11 from dukefirehawk/angel3

Fixed requireAuthentication
This commit is contained in:
Thomas Hii 2021-10-04 13:17:05 +08:00 committed by GitHub
commit 94713ddbd6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
37 changed files with 167 additions and 161 deletions

View file

@ -1,5 +1,9 @@
# Change Log
## 4.1.2
* Fixed `requireAuthentication` to work correctly with null-safety type
## 4.1.1
* Changed `userId` field of `AuthToken` to String type

View file

@ -125,10 +125,10 @@ class AngelAuth<User> {
.registerLazySingleton<Future<_AuthResult<User>>>((container) async {
var req = container.make<RequestContext>();
var res = container.make<ResponseContext>();
if (req == null || res == null) {
_log.warning('RequestContext or responseContext is null');
throw AngelHttpException.forbidden();
}
//if (req == null || res == null) {
// _log.warning('RequestContext or responseContext is null');
// throw AngelHttpException.forbidden();
//}
var result = await _decodeJwt(req, res);
if (result != null) {
@ -139,14 +139,14 @@ class AngelAuth<User> {
}
});
appContainer.registerLazySingleton<Future<User?>>((container) async {
appContainer.registerLazySingleton<Future<User>>((container) async {
var result = await container.makeAsync<_AuthResult<User>>();
return result?.user;
return result.user;
});
appContainer.registerLazySingleton<Future<AuthToken?>>((container) async {
appContainer.registerLazySingleton<Future<AuthToken>>((container) async {
var result = await container.makeAsync<_AuthResult<User>>();
return result?.token;
return result.token;
});
}

View file

@ -1,6 +1,6 @@
name: angel3_auth
description: A complete authentication plugin for Angel3. Includes support for stateless JWT tokens, Basic Auth, and more.
version: 4.1.1
version: 4.1.2
homepage: https://angel3-framework.web.app/
repository: https://github.com/dukefirehawk/angel/tree/master/packages/auth
environment:
@ -20,6 +20,8 @@ dev_dependencies:
io: ^1.0.0
test: ^1.17.4
lints: ^1.0.0
#dependency_overrides:
# angel3_framework:
# path: ../framework
dependency_overrides:
angel3_container:
path: ../container/angel_container
angel3_framework:
path: ../framework

View file

@ -1,16 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.pub" />
<excludeFolder url="file://$MODULE_DIR$/.tmp" />
<excludeFolder url="file://$MODULE_DIR$/build" />
<excludeFolder url="file://$MODULE_DIR$/temp" />
<excludeFolder url="file://$MODULE_DIR$/tmp" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Dart SDK" level="project" />
<orderEntry type="library" name="Dart Packages" level="project" />
</component>
</module>

View file

@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/auth_oauth2.iml" filepath="$PROJECT_DIR$/.idea/auth_oauth2.iml" />
</modules>
</component>
</project>

View file

@ -1,7 +0,0 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Github Auth Server" type="DartCommandLineRunConfigurationType" factoryName="Dart Command Line Application" singleton="true">
<option name="filePath" value="$PROJECT_DIR$/example/main.dart" />
<option name="workingDirectory" value="$PROJECT_DIR$" />
<method />
</configuration>
</component>

View file

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

View file

@ -1,7 +1,7 @@
# Angel3 OAuth2 Handler
![Pub Version (including pre-releases)](https://img.shields.io/pub/v/angel3_auth_oauth2?include_prereleases)
![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)
[![License](https://img.shields.io/github/license/dukefirehawk/angel)](https://github.com/dukefirehawk/angel/tree/master/packages/auth_oauth2/LICENSE)

View file

@ -13,7 +13,3 @@ dependencies:
dev_dependencies:
logging: ^1.0.1
lints: ^1.0.0
#dependency_overrides:
# angel3_auth:
# path: ../auth

View file

@ -1,5 +1,16 @@
# 2.0.0
# Change Log
## 4.0.0
* Migrated to support Dart SDK 2.12.x NNBD
## 3.0.0
* Migrated to work with Dart SDK 2.12.x Non NNBD
## 2.0.0
* Angel 2 + Dart 2 suppport.
* Use `package:twitter` instead of `package:twit`.
* Add `TwitterAuthorizationException`.
* Add `onError` callback.
* Add `onError` callback.

View file

@ -1,4 +1,10 @@
# auth_twitter
angel_auth strategy for Twitter login.
# Angel3 Auth Twitter
See the [example](example/server.dart);
![Pub Version (including pre-releases)](https://img.shields.io/pub/v/angel3_auth_twitter?include_prereleases)
![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)
[![License](https://img.shields.io/github/license/dukefirehawk/angel)](https://github.com/dukefirehawk/angel/tree/master/packages/auth_twitter/LICENSE)
Angel3 authentication strategy for Twitter login.
See the [example](example/server.dart);

View file

@ -1,4 +1 @@
include: package:pedantic/analysis_options.yaml
analyzer:
strong-mode:
implicit-casts: false
include: package:lints/recommended.yaml

View file

@ -1,21 +1,13 @@
name: "angel_auth_twitter"
name: "angel3_auth_twitter"
version: 3.0.0
description: "package:angel_auth strategy for Twitter login. Auto-signs requests."
description: "package:angel3_auth strategy for Twitter login. Auto-signs requests."
homepage: "https://github.com/angel-dart/auth_twitter.git"
publish_to: none
environment:
sdk: ">=2.10.0 <3.0.0"
dependencies:
angel_auth:
git:
url: https://github.com/dukefirehawk/angel.git
ref: sdk-2.12.x
path: packages/auth
angel_framework:
git:
url: https://github.com/dukefirehawk/angel.git
ref: sdk-2.12.x
path: packages/framework
http: ^0.13.0
path: ^1.0.0
twitter:

View file

@ -24,7 +24,3 @@ dev_dependencies:
build_web_compilers: ^3.2.1
test: ^1.17.5
lints: ^1.0.0
#dependency_overrides:
# angel3_auth:
# path: ../auth

View file

@ -3,6 +3,7 @@
## 3.1.1
* Updated `_ReflectedMethodMirror` to have optional `returnType` parameter
* Updated all the methods of `Container` class to return non nullable type
## 3.1.0

View file

@ -17,7 +17,7 @@ Future<void> main() async {
// Register a factory that creates a truck.
container.registerFactory<Truck>((container) {
return _TruckImpl(container.make<Engine>()!);
return _TruckImpl(container.make<Engine>());
});
// Use `make` to create an instance.
@ -28,16 +28,16 @@ Future<void> main() async {
print(await container.makeAsync<int>());
// Asynchronous resolution also works for plain objects.
await container.makeAsync<Truck>()?.then((t) => t.drive());
await container.makeAsync<Truck>().then((t) => t.drive());
// Register a named singleton.
container.registerNamedSingleton('the_truck', truck);
// Should print: 'Vroom! I have 40 horsepower in my engine.'
truck?.drive();
truck.drive();
// Should print the same.
container.findByName<Truck>('the_truck')?.drive();
container.findByName<Truck>('the_truck').drive();
// We can make a child container with its own factory.
var childContainer = container.createChild();
@ -47,10 +47,10 @@ Future<void> main() async {
});
// Make a truck with 5666 HP.
childContainer.make<Truck>()?.drive();
childContainer.make<Truck>().drive();
// However, calling `make<Engine>` will return the Engine singleton we created above.
print(childContainer.make<Engine>()?.horsePower);
print(childContainer.make<Engine>().horsePower);
}
abstract class Truck {

View file

@ -23,14 +23,19 @@ class Container {
}
/// Determines if the container has an injection of the given type.
bool has<T>([Type? t]) {
Container? search = this;
t ??= T == dynamic ? t : T;
bool has<T>([Type? type]) {
var t2 = T;
if (type != null) {
t2 = type;
} else if (T == dynamic && type == null) {
return false;
}
Container? search = this;
while (search != null) {
if (search._singletons.containsKey(t)) {
if (search._singletons.containsKey(t2)) {
return true;
} else if (search._factories.containsKey(t)) {
} else if (search._factories.containsKey(t2)) {
return true;
} else {
search = search._parent;
@ -59,27 +64,31 @@ class Container {
///
/// It is similar to [make], but resolves an injection of either
/// `Future<T>` or `T`.
Future<T>? makeAsync<T>([Type? type]) {
type ??= T;
Future<T> makeAsync<T>([Type? type]) {
var t2 = T;
if (type != null) {
t2 = type;
}
Type? futureType; //.Future<T>.value(null).runtimeType;
if (T == dynamic) {
try {
futureType = reflector.reflectFutureOf(type).reflectedType;
futureType = reflector.reflectFutureOf(t2).reflectedType;
} on UnsupportedError {
// Ignore this.
}
}
if (has<T>(type)) {
return Future<T>.value(make(type));
if (has<T>(t2)) {
return Future<T>.value(make(t2));
} else if (has<Future<T>>()) {
return make<Future<T>>();
} else if (futureType != null) {
return make(futureType);
} else {
throw ReflectionException(
'No injection for Future<$type> or $type was found.');
'No injection for Future<$t2> or $t2 was found.');
}
}
@ -87,24 +96,27 @@ class Container {
///
/// In contexts where a static generic type cannot be used, use
/// the [type] argument, instead of [T].
T? make<T>([Type? type]) {
type ??= T;
T make<T>([Type? type]) {
var t2 = T;
if (type != null) {
t2 = type;
}
Container? search = this;
while (search != null) {
if (search._singletons.containsKey(type)) {
if (search._singletons.containsKey(t2)) {
// Find a singleton, if any.
return search._singletons[type] as T?;
} else if (search._factories.containsKey(type)) {
return search._singletons[t2] as T;
} else if (search._factories.containsKey(t2)) {
// Find a factory, if any.
return search._factories[type]!(this) as T?;
return search._factories[t2]!(this) as T;
} else {
search = search._parent;
}
}
var reflectedType = reflector.reflectType(type);
var reflectedType = reflector.reflectType(t2);
var positional = [];
var named = <String, dynamic>{};
@ -131,10 +143,10 @@ class Container {
return reflectedType.newInstance(
isDefault(constructor.name) ? '' : constructor.name,
positional,
named, []).reflectee as T?;
named, []).reflectee as T;
} else {
throw ReflectionException(
'$type is not a class, and therefore cannot be instantiated.');
'$t2 is not a class, and therefore cannot be instantiated.');
}
}
@ -161,13 +173,16 @@ class Container {
/// Returns [f].
T Function(Container) registerFactory<T>(T Function(Container) f,
{Type? as}) {
as ??= T;
if (_factories.containsKey(as)) {
throw StateError('This container already has a factory for $as.');
Type t2 = T;
if (as != null) {
t2 = as;
}
_factories[as] = f;
if (_factories.containsKey(t2)) {
throw StateError('This container already has a factory for $t2.');
}
_factories[t2] = f;
return f;
}
@ -176,14 +191,19 @@ class Container {
///
/// Returns [object].
T registerSingleton<T>(T object, {Type? as}) {
as ??= T == dynamic ? as : T;
Type t2 = T;
if (as != null) {
t2 = as;
} else if (T == dynamic) {
t2 = as ?? object.runtimeType;
}
//as ??= T == dynamic ? as : T;
if (_singletons.containsKey(as ?? object.runtimeType)) {
throw StateError(
'This container already has a singleton for ${as ?? object.runtimeType}.');
if (_singletons.containsKey(t2)) {
throw StateError('This container already has a singleton for $t2.');
}
_singletons[as ?? object.runtimeType] = object;
_singletons[t2] = object;
return object;
}
@ -193,9 +213,9 @@ class Container {
///
/// [findByName] is best reserved for internal logic that end users of code should
/// not see.
T? findByName<T>(String name) {
T findByName<T>(String name) {
if (_namedSingletons.containsKey(name)) {
return _namedSingletons[name] as T?;
return _namedSingletons[name] as T;
} else if (_parent != null) {
return _parent!.findByName<T>(name);
} else {

View file

@ -1,6 +1,6 @@
name: angel3_container
version: 3.1.1
description: A hierarchical DI container, and pluggable backends for reflection.
description: Angel3 hierarchical DI container, and pluggable backends for reflection.
homepage: https://angel3-framework.web.app/
repository: https://github.com/dukefirehawk/angel/tree/master/packages/container/angel_container
environment:

View file

@ -67,7 +67,7 @@ void testReflector(Reflector reflector) {
});
test('constructor injects singleton', () {
var lower = container.make<LowerPokemon>()!;
var lower = container.make<LowerPokemon>();
expect(lower.lowercaseName, blaziken.name.toLowerCase());
});

View file

@ -24,7 +24,8 @@ void main() {
});
test('has on singleton', () {
expect(container.has<Song>(), true);
var result = container.has<Song>();
expect(result, true);
});
test('has on factory', () {

View file

@ -10,7 +10,7 @@ void main() {
});
test('fetch by name', () {
expect(container.findByName<Foo>('foo')!.bar, 'baz');
expect(container.findByName<Foo>('foo').bar, 'baz');
});
test('cannot redefine', () {

View file

@ -1,5 +1,9 @@
# Change Log
## 3.0.1
* Updated `package:angel3_container`
## 3.0.0
* Fixed NNBD issues

View file

@ -18,7 +18,7 @@ Future<void> main() async {
// Register a factory that creates a truck.
container.registerFactory<Truck>((container) {
return _TruckImpl(container.make<Engine>()!);
return _TruckImpl(container.make<Engine>());
});
// Use `make` to create an instance.
@ -29,16 +29,16 @@ Future<void> main() async {
print(await container.makeAsync<int>());
// Asynchronous resolution also works for plain objects.
await container.makeAsync<Truck>()?.then((t) => t.drive());
await container.makeAsync<Truck>().then((t) => t.drive());
// Register a named singleton.
container.registerNamedSingleton('the_truck', truck);
// Should print: 'Vroom! I have 40 horsepower in my engine.'
truck?.drive();
truck.drive();
// Should print the same.
container.findByName<Truck>('the_truck')?.drive();
container.findByName<Truck>('the_truck').drive();
// We can make a child container with its own factory.
var childContainer = container.createChild();
@ -48,10 +48,10 @@ Future<void> main() async {
});
// Make a truck with 5666 HP.
childContainer.make<Truck>()?.drive();
childContainer.make<Truck>().drive();
// However, calling `make<Engine>` will return the Engine singleton we created above.
print(childContainer.make<Engine>()?.horsePower);
print(childContainer.make<Engine>().horsePower);
}
abstract class Truck {

View file

@ -1,5 +1,5 @@
name: angel3_container_generator
version: 3.0.0
version: 3.0.1
description: Codegen support for using pkg:reflectable with pkg:angel3_container.
homepage: https://angel3-framework.web.app/
repository: https://github.com/dukefirehawk/angel/tree/master/packages/container/angel_container_generator
@ -13,6 +13,6 @@ dev_dependencies:
build_test: ^2.1.3
test: ^1.17.5
lints: ^1.0.1
dependency_overrides:
dependency_overrides:
angel3_container:
path: ../angel_container
path: ../container/angel_container

View file

@ -27,7 +27,7 @@ void main() {
});
test('inject constructor parameters', () {
var album = container.make<Album>()!;
var album = container.make<Album>();
print(album.title);
expect(album.title, 'flowers by stevie wonder');
});
@ -93,7 +93,7 @@ void testReflector(Reflector reflector) {
});
test('constructor injects singleton', () {
var lower = container.make<LowerPokemon>()!;
var lower = container.make<LowerPokemon>();
expect(lower.lowercaseName, blaziken.name.toLowerCase());
});

View file

@ -1,9 +1,13 @@
# Change Log
## 4.2.1
* Updated `package:angel3_container`
## 4.2.0
* Updated to use `package:belatuk_combinator`
* Updated to use `package:belatuk_merge_map`
* Updated to `package:belatuk_combinator`
* Updated to `package:belatuk_merge_map`
* Updated linter to `package:lints`
## 4.1.3

View file

@ -292,13 +292,14 @@ abstract class Driver<
{bool ignoreFinalizers = false}) {
if (req == null || res == null) {
try {
app.logger?.severe(null, e, st);
app.logger?.severe('500 Internal Server Error', e, st);
setStatusCode(response, 500);
writeStringToResponse(response, '500 Internal Server Error');
closeResponse(response);
} finally {
return Future.value();
} catch (e) {
app.logger?.severe('500 Internal Server Error', e);
}
return Future.value();
}
Future handleError;
@ -327,7 +328,7 @@ abstract class Driver<
req.container!.has<Stopwatch>()) {
var sw = req.container!.make<Stopwatch>();
app.logger?.info(
"${res.statusCode} ${req.method} ${req.uri} (${sw?.elapsedMilliseconds ?? 'unknown'} ms)");
"${res.statusCode} ${req.method} ${req.uri} (${sw.elapsedMilliseconds} ms)");
}
return req.close();
}

View file

@ -307,7 +307,9 @@ abstract class ResponseContext<RawResponse>
/// Serializes data to the response.
Future<bool> serialize(value, {MediaType? contentType}) async {
if (!isOpen) throw closed();
if (!isOpen) {
throw closed();
}
this.contentType = contentType ?? MediaType('application', 'json');
var text = await serializer(value);
if (text.isEmpty) return true;
@ -320,7 +322,9 @@ abstract class ResponseContext<RawResponse>
///
/// `HEAD` responses will not actually write data.
Future streamFile(File file) async {
if (!isOpen) throw closed();
if (!isOpen) {
throw closed();
}
var mimeType = app!.mimeTypeResolver.lookup(file.path);
contentLength = await file.length();
contentType = mimeType == null

View file

@ -288,7 +288,12 @@ class Angel extends Routable {
dynamic findProperty(key) {
if (configuration.containsKey(key)) return configuration[key];
return parent != null ? parent?.findProperty(key) : null;
//return parent != null ? parent?.findProperty(key) : null;
if (parent != null) {
return parent?.findProperty(key);
}
return null;
}
/// Runs several optimizations, *if* [angelEnv.isProduction] is `true`.
@ -345,7 +350,7 @@ class Angel extends Routable {
///
/// If you are on `Dart >=2.0.0`, simply call `mountController<T>()`.
Future<T> mountController<T extends Controller>([Type? type]) {
var controller = container!.make<T>(type)!;
var controller = container!.make<T>(type);
return configure(controller.configureServer).then((_) => controller);
}

View file

@ -1,5 +1,5 @@
name: angel3_framework
version: 4.2.0
version: 4.2.1
description: A high-powered HTTP server extensible framework with dependency injection, routing and much more.
homepage: https://angel3-framework.web.app/
repository: https://github.com/dukefirehawk/angel/tree/master/packages/framework
@ -35,6 +35,6 @@ dev_dependencies:
io: ^1.0.0
test: ^1.17.5
lints: ^1.0.0
#dependency_overrides:
# angel3_container:
# path: ../container/angel_container
dependency_overrides:
angel3_container:
path: ../container/angel_container

View file

@ -27,7 +27,7 @@ void main() {
// Inject some todos
app.container!.registerSingleton(Todo(text: TEXT, over: OVER));
app.container!.registerFactory<Future<Foo>>((container) async {
var req = container.make<RequestContext>()!;
var req = container.make<RequestContext>();
var text = await utf8.decoder.bind(req.body!).join();
return Foo(text);
});

View file

@ -14,6 +14,3 @@ dependencies:
logging: ^1.0.1
dev_dependencies:
lints: ^1.0.1
#dependency_overrides:
# angel3_container:
# path: ../container/angel_container

View file

@ -21,6 +21,3 @@ dev_dependencies:
shelf_static: ^1.0.0
test: ^1.17.5
lints: ^1.0.0
#dependency_overrides:
# angel3_container:
# path: ../container/angel_container

View file

@ -19,7 +19,4 @@ dependencies:
dev_dependencies:
test: ^1.17.5
lints: ^1.0.0
#dependency_overrides:
# angel3_websocket:
# path: ../websocket

View file

@ -1,5 +1,9 @@
# Change Log
## 4.1.2
* Updated `package:angel3_container`
## 4.1.1
* Fixed issue with type casting
@ -7,7 +11,7 @@
## 4.1.0
* Updated to use `package:belatuk_merge_map`
* Updated `package:belatuk_merge_map`
* Updated linter to `package:lints`
## 4.0.1

View file

@ -275,7 +275,7 @@ class AngelWebSocket {
action.params?['query'] is Map &&
action.params?['query']['jwt'] is String) {
try {
var auth = socket.request.container!.make<AngelAuth>()!;
var auth = socket.request.container!.make<AngelAuth>();
var jwt = action.params!['query']['jwt'] as String;
AuthToken token;

View file

@ -1,5 +1,5 @@
name: angel3_websocket
version: 4.1.1
version: 4.1.2
description: This library provides WebSockets support for Angel3 framework.
homepage: https://angel3-framework.web.app/
repository: https://github.com/dukefirehawk/angel/tree/master/packages/websocket
@ -22,7 +22,11 @@ dev_dependencies:
angel3_model: ^3.1.0
test: ^1.17.5
lints: ^1.0.0
#dependency_overrides:
# angel3_auth:
# path: ../auth
dependency_overrides:
angel3_container:
path: ../container/angel_container
angel3_auth:
path: ../auth
angel3_framework:
path: ../framework