2
This commit is contained in:
parent
456f4f3d01
commit
a36b191650
3 changed files with 19 additions and 9 deletions
|
@ -1,3 +1,6 @@
|
||||||
|
# 1.1.1+2
|
||||||
|
* `_apply` now always sends a `token` cookie.
|
||||||
|
|
||||||
# 1.1.1+1
|
# 1.1.1+1
|
||||||
* Update `protectCookie` to only send `maxAge` when it is not `-1`.
|
* Update `protectCookie` to only send `maxAge` when it is not `-1`.
|
||||||
|
|
||||||
|
|
|
@ -109,10 +109,15 @@ class AngelAuth<T> {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void _apply(RequestContext req, AuthToken token, user) {
|
void _apply(RequestContext req, ResponseContext res, AuthToken token, user) {
|
||||||
req
|
req
|
||||||
..inject(AuthToken, req.properties['token'] = token)
|
..inject(AuthToken, req.properties['token'] = token)
|
||||||
..inject(user.runtimeType, req.properties["user"] = user);
|
..inject(user.runtimeType, req.properties["user"] = user);
|
||||||
|
|
||||||
|
if (allowCookie == true) {
|
||||||
|
res.cookies
|
||||||
|
.add(protectCookie(new Cookie('token', token.serialize(_hs256))));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A middleware that decodes a JWT from a request, and injects a corresponding user.
|
/// A middleware that decodes a JWT from a request, and injects a corresponding user.
|
||||||
|
@ -140,7 +145,7 @@ class AngelAuth<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
final user = await deserializer(token.userId);
|
final user = await deserializer(token.userId);
|
||||||
_apply(req, token, user);
|
_apply(req, res, token, user);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -173,8 +178,9 @@ class AngelAuth<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_jwtLifeSpan > 0) {
|
if (_jwtLifeSpan > 0) {
|
||||||
cookie.maxAge ??=
|
cookie.maxAge ??= _jwtLifeSpan < 0
|
||||||
_jwtLifeSpan < 0 ? -1 : _jwtLifeSpan ~/ Duration.millisecondsPerSecond;
|
? -1
|
||||||
|
: _jwtLifeSpan ~/ Duration.millisecondsPerSecond;
|
||||||
cookie.expires ??=
|
cookie.expires ??=
|
||||||
new DateTime.now().add(new Duration(milliseconds: _jwtLifeSpan));
|
new DateTime.now().add(new Duration(milliseconds: _jwtLifeSpan));
|
||||||
}
|
}
|
||||||
|
@ -203,7 +209,8 @@ class AngelAuth<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (token.lifeSpan > -1) {
|
if (token.lifeSpan > -1) {
|
||||||
token.issuedAt.add(new Duration(milliseconds: token.lifeSpan.toInt()));
|
token.issuedAt
|
||||||
|
.add(new Duration(milliseconds: token.lifeSpan.toInt()));
|
||||||
|
|
||||||
if (!token.issuedAt.isAfter(new DateTime.now())) {
|
if (!token.issuedAt.isAfter(new DateTime.now())) {
|
||||||
print(
|
print(
|
||||||
|
@ -272,7 +279,7 @@ class AngelAuth<T> {
|
||||||
if (r != null) return r;
|
if (r != null) return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
_apply(req, token, result);
|
_apply(req, res, token, result);
|
||||||
|
|
||||||
if (allowCookie)
|
if (allowCookie)
|
||||||
res.cookies.add(protectCookie(new Cookie("token", jwt)));
|
res.cookies.add(protectCookie(new Cookie("token", jwt)));
|
||||||
|
@ -312,7 +319,7 @@ class AngelAuth<T> {
|
||||||
/// Log a user in on-demand.
|
/// Log a user in on-demand.
|
||||||
Future login(AuthToken token, RequestContext req, ResponseContext res) async {
|
Future login(AuthToken token, RequestContext req, ResponseContext res) async {
|
||||||
var user = await deserializer(token.userId);
|
var user = await deserializer(token.userId);
|
||||||
_apply(req, token, user);
|
_apply(req, res, token, user);
|
||||||
_onLogin.add(user);
|
_onLogin.add(user);
|
||||||
|
|
||||||
if (allowCookie)
|
if (allowCookie)
|
||||||
|
@ -325,7 +332,7 @@ class AngelAuth<T> {
|
||||||
var user = await deserializer(userId);
|
var user = await deserializer(userId);
|
||||||
var token = new AuthToken(
|
var token = new AuthToken(
|
||||||
userId: userId, lifeSpan: _jwtLifeSpan, ipAddress: req.ip);
|
userId: userId, lifeSpan: _jwtLifeSpan, ipAddress: req.ip);
|
||||||
_apply(req, token, user);
|
_apply(req, res, token, user);
|
||||||
_onLogin.add(user);
|
_onLogin.add(user);
|
||||||
|
|
||||||
if (allowCookie)
|
if (allowCookie)
|
||||||
|
|
|
@ -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.1.1+1
|
version: 1.1.1+2
|
||||||
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
|
||||||
environment:
|
environment:
|
||||||
|
|
Loading…
Reference in a new issue