+1
This commit is contained in:
parent
9fc970e77a
commit
2cae916e39
2 changed files with 14 additions and 22 deletions
|
@ -2,9 +2,6 @@ import 'dart:async';
|
|||
import 'dart:io';
|
||||
import 'package:angel_framework/angel_framework.dart';
|
||||
|
||||
/// Restricts access to a resource via authentication. Constant instance.
|
||||
const RequestMiddleware requireAuth = const RequireAuthorizationMiddleware();
|
||||
|
||||
/// Forces Basic authentication over the requested resource, with the given [realm] name, if no JWT is present.
|
||||
///
|
||||
/// [realm] defaults to `'angel_auth'`.
|
||||
|
@ -22,23 +19,18 @@ RequestHandler forceBasicAuth({String realm}) {
|
|||
}
|
||||
|
||||
/// Restricts access to a resource via authentication.
|
||||
class RequireAuthorizationMiddleware implements AngelMiddleware {
|
||||
const RequireAuthorizationMiddleware();
|
||||
|
||||
@override
|
||||
Future<bool> call(RequestContext req, ResponseContext res,
|
||||
{bool throwError: true}) async {
|
||||
bool _reject(ResponseContext res) {
|
||||
if (throwError) {
|
||||
res.statusCode = HttpStatus.FORBIDDEN;
|
||||
throw new AngelHttpException.forbidden();
|
||||
} else
|
||||
return false;
|
||||
}
|
||||
|
||||
if (req.properties.containsKey('user') || req.method == 'OPTIONS')
|
||||
return true;
|
||||
else
|
||||
return _reject(res);
|
||||
Future<bool> requireAuth(RequestContext req, ResponseContext res,
|
||||
{bool throwError: true}) async {
|
||||
bool _reject(ResponseContext res) {
|
||||
if (throwError) {
|
||||
res.statusCode = HttpStatus.FORBIDDEN;
|
||||
throw new AngelHttpException.forbidden();
|
||||
} else
|
||||
return false;
|
||||
}
|
||||
|
||||
if (req.properties.containsKey('user') || req.method == 'OPTIONS')
|
||||
return true;
|
||||
else
|
||||
return _reject(res);
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
name: angel_auth
|
||||
description: A complete authentication plugin for Angel.
|
||||
version: 1.1.0-alpha
|
||||
version: 1.1.0-alpha+1
|
||||
author: Tobe O <thosakwe@gmail.com>
|
||||
homepage: https://github.com/angel-dart/angel_auth
|
||||
environment:
|
||||
|
|
Loading…
Reference in a new issue