12
This commit is contained in:
parent
148c9cbc18
commit
0de70bfc72
3 changed files with 18 additions and 13 deletions
|
@ -1,6 +1,6 @@
|
||||||
# angel_auth
|
# angel_auth
|
||||||
|
|
||||||
![version 1.1.0-dev+11](https://img.shields.io/badge/version-1.1.0--dev+11-red.svg)
|
![version 1.1.0-dev+12](https://img.shields.io/badge/version-1.1.0--dev+12-red.svg)
|
||||||
![build status](https://travis-ci.org/angel-dart/auth.svg?branch=master)
|
![build status](https://travis-ci.org/angel-dart/auth.svg?branch=master)
|
||||||
|
|
||||||
A complete authentication plugin for Angel. Inspired by Passport.
|
A complete authentication plugin for Angel. Inspired by Passport.
|
||||||
|
|
|
@ -92,8 +92,8 @@ class AngelAuth extends AngelPlugin {
|
||||||
|
|
||||||
if (enforceIp) {
|
if (enforceIp) {
|
||||||
if (debug) {
|
if (debug) {
|
||||||
print(
|
print('Token IP: ${token.ipAddress}. Current request sent from: ${req
|
||||||
'Token IP: ${token.ipAddress}. Current request sent from: ${req.ip}');
|
.ip}');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (req.ip != null && req.ip != token.ipAddress)
|
if (req.ip != null && req.ip != token.ipAddress)
|
||||||
|
@ -140,8 +140,9 @@ class AngelAuth extends AngelPlugin {
|
||||||
// Allow Basic auth to fall through
|
// Allow Basic auth to fall through
|
||||||
if (_rgxBearer.hasMatch(authHeader))
|
if (_rgxBearer.hasMatch(authHeader))
|
||||||
return authHeader.replaceAll(_rgxBearer, "").trim();
|
return authHeader.replaceAll(_rgxBearer, "").trim();
|
||||||
} else if (req.cookies.any((cookie) => cookie.name == "token")) {
|
} else if (allowCookie &&
|
||||||
print('Request has "token" cookie...');
|
req.cookies.any((cookie) => cookie.name == "token")) {
|
||||||
|
if (debug) print('Request has "token" cookie...');
|
||||||
return req.cookies.firstWhere((cookie) => cookie.name == "token").value;
|
return req.cookies.firstWhere((cookie) => cookie.name == "token").value;
|
||||||
} else if (allowTokenInQuery && req.query['token'] is String) {
|
} else if (allowTokenInQuery && req.query['token'] is String) {
|
||||||
return req.query['token'];
|
return req.query['token'];
|
||||||
|
@ -168,7 +169,8 @@ class AngelAuth extends AngelPlugin {
|
||||||
if (enforceIp) {
|
if (enforceIp) {
|
||||||
if (debug)
|
if (debug)
|
||||||
print(
|
print(
|
||||||
'Token IP: ${token.ipAddress}. Current request sent from: ${req.ip}');
|
'Token IP: ${token.ipAddress}. Current request sent from: ${req
|
||||||
|
.ip}');
|
||||||
|
|
||||||
if (req.ip != token.ipAddress)
|
if (req.ip != token.ipAddress)
|
||||||
throw new AngelHttpException.Forbidden(
|
throw new AngelHttpException.Forbidden(
|
||||||
|
@ -177,8 +179,8 @@ class AngelAuth extends AngelPlugin {
|
||||||
|
|
||||||
if (token.lifeSpan > -1) {
|
if (token.lifeSpan > -1) {
|
||||||
if (debug) {
|
if (debug) {
|
||||||
print(
|
print('Checking if token has expired... Life span is ${token
|
||||||
'Checking if token has expired... Life span is ${token.lifeSpan}');
|
.lifeSpan}');
|
||||||
}
|
}
|
||||||
|
|
||||||
token.issuedAt.add(new Duration(milliseconds: token.lifeSpan));
|
token.issuedAt.add(new Duration(milliseconds: token.lifeSpan));
|
||||||
|
@ -199,8 +201,11 @@ class AngelAuth extends AngelPlugin {
|
||||||
print('Final, valid token: ${token.toJson()}');
|
print('Final, valid token: ${token.toJson()}');
|
||||||
}
|
}
|
||||||
|
|
||||||
res.cookies.add(new Cookie('token', token.serialize(_hs256)));
|
if (allowCookie)
|
||||||
return token.toJson();
|
res.cookies.add(new Cookie('token', token.serialize(_hs256)));
|
||||||
|
|
||||||
|
final data = await deserializer(token.userId);
|
||||||
|
return {'data': data, 'token': token.serialize(_hs256)};
|
||||||
}
|
}
|
||||||
} catch (e, st) {
|
} catch (e, st) {
|
||||||
if (debug) {
|
if (debug) {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
name: angel_auth
|
name: angel_auth
|
||||||
description: A complete authentication plugin for Angel.
|
description: A complete authentication plugin for Angel.
|
||||||
version: 1.0.0-dev+11
|
version: 1.0.0-dev+12
|
||||||
author: Tobe O <thosakwe@gmail.com>
|
author: Tobe O <thosakwe@gmail.com>
|
||||||
homepage: https://github.com/angel-dart/angel_auth
|
homepage: https://github.com/angel-dart/angel_auth
|
||||||
dependencies:
|
dependencies:
|
||||||
|
|
Loading…
Reference in a new issue