:)
This commit is contained in:
parent
a504ac46e6
commit
3e81778155
7 changed files with 15 additions and 18 deletions
|
@ -1,6 +1,6 @@
|
|||
# angel_auth
|
||||
|
||||
[![version 1.1.0-dev+14](https://img.shields.io/badge/version-1.1.0--dev+14-red.svg)](https://pub.dartlang.org/packages/angel_auth)
|
||||
[![version 1.1.0-dev+15](https://img.shields.io/badge/version-1.1.0--dev+15-red.svg)](https://pub.dartlang.org/packages/angel_auth)
|
||||
![build status](https://travis-ci.org/angel-dart/auth.svg?branch=master)
|
||||
|
||||
A complete authentication plugin for Angel. Inspired by Passport.
|
||||
|
|
|
@ -33,7 +33,7 @@ class AuthToken {
|
|||
if (split.length != 3)
|
||||
throw new AngelHttpException.NotAuthenticated(message: "Invalid JWT.");
|
||||
|
||||
var headerString = new String.fromCharCodes(BASE64URL.decode(split[0]));
|
||||
// var headerString = new String.fromCharCodes(BASE64URL.decode(split[0]));
|
||||
var payloadString = new String.fromCharCodes(BASE64URL.decode(split[1]));
|
||||
var data = split[0] + "." + split[1];
|
||||
var signature = BASE64URL.encode(hmac.convert(data.codeUnits).bytes);
|
||||
|
|
|
@ -3,13 +3,13 @@ import 'dart:io';
|
|||
import 'package:angel_framework/angel_framework.dart';
|
||||
|
||||
/// Restricts access to a resource via authentication.
|
||||
class RequireAuthorizationMiddleware extends BaseMiddleware {
|
||||
class RequireAuthorizationMiddleware extends AngelMiddleware {
|
||||
@override
|
||||
Future<bool> call(RequestContext req, ResponseContext res,
|
||||
{bool throwError: true}) async {
|
||||
bool _reject(ResponseContext res) {
|
||||
if (throwError) {
|
||||
res.status(HttpStatus.FORBIDDEN);
|
||||
res.statusCode = HttpStatus.FORBIDDEN;
|
||||
throw new AngelHttpException.Forbidden();
|
||||
} else
|
||||
return false;
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
import 'package:angel_framework/angel_framework.dart';
|
||||
import 'auth_token.dart';
|
||||
|
||||
typedef AngelAuthCallback(
|
||||
RequestContext req, ResponseContext res, AuthToken token);
|
||||
RequestContext req, ResponseContext res, String token);
|
||||
|
||||
class AngelAuthOptions {
|
||||
AngelAuthCallback callback;
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
import 'dart:async';
|
||||
import 'dart:collection';
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
import 'dart:math' as Math;
|
||||
import 'package:angel_framework/angel_framework.dart';
|
||||
|
@ -233,10 +231,12 @@ class AngelAuth extends AngelPlugin {
|
|||
var userId = await serializer(result);
|
||||
|
||||
// Create JWT
|
||||
var jwt = new AuthToken(
|
||||
userId: userId, lifeSpan: _jwtLifeSpan, ipAddress: req.ip)
|
||||
.serialize(_hs256);
|
||||
req.inject(AuthToken, jwt);
|
||||
var token = new AuthToken(
|
||||
userId: userId, lifeSpan: _jwtLifeSpan, ipAddress: req.ip);
|
||||
var jwt = token.serialize(_hs256);
|
||||
req
|
||||
..inject(AuthToken, req.properties['token'] = token)
|
||||
..inject(result.runtimeType, req.properties["user"] = result);
|
||||
|
||||
if (allowCookie) req.cookies.add(new Cookie("token", jwt));
|
||||
|
||||
|
|
|
@ -3,7 +3,6 @@ import 'dart:convert';
|
|||
import 'dart:io';
|
||||
import 'package:angel_framework/angel_framework.dart';
|
||||
import '../options.dart';
|
||||
import '../plugin.dart';
|
||||
import '../strategy.dart';
|
||||
|
||||
bool _validateString(String str) => str != null && str.isNotEmpty;
|
||||
|
@ -32,8 +31,7 @@ class LocalAuthStrategy extends AuthStrategy {
|
|||
'Please provide a valid username and password.',
|
||||
bool this.allowBasic: true,
|
||||
bool this.forceBasic: false,
|
||||
String this.realm: 'Authentication is required.'}) {
|
||||
}
|
||||
String this.realm: 'Authentication is required.'}) {}
|
||||
|
||||
@override
|
||||
Future<bool> canLogout(RequestContext req, ResponseContext res) async {
|
||||
|
@ -79,8 +77,8 @@ class LocalAuthStrategy extends AuthStrategy {
|
|||
|
||||
if (forceBasic) {
|
||||
res
|
||||
..status(401)
|
||||
..header(HttpHeaders.WWW_AUTHENTICATE, 'Basic realm="$realm"')
|
||||
..statusCode = 401
|
||||
..headers[HttpHeaders.WWW_AUTHENTICATE] = 'Basic realm="$realm"'
|
||||
..end();
|
||||
return false;
|
||||
} else
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
name: angel_auth
|
||||
description: A complete authentication plugin for Angel.
|
||||
version: 1.0.0-dev+14
|
||||
version: 1.0.0-dev+15
|
||||
author: Tobe O <thosakwe@gmail.com>
|
||||
homepage: https://github.com/angel-dart/angel_auth
|
||||
dependencies:
|
||||
|
|
Loading…
Reference in a new issue