Fixed auth analysis warnings

This commit is contained in:
thomashii@dukefirehawk.com 2022-08-17 11:17:00 +08:00
parent ba26c88d6b
commit 5402fa55a9
3 changed files with 8 additions and 7 deletions

View file

@ -17,6 +17,7 @@ void main() async {
// If authentication succeeds, return a User object.
//
// Otherwise, return `null`.
return null;
});
app.post('/auth/local', auth.authenticate('local'));

View file

@ -86,7 +86,7 @@ class AuthToken {
// var headerString = decodeBase64(split[0]);
var payloadString = decodeBase64(split[1]);
var data = split[0] + '.' + split[1];
var data = '${split[0]}.${split[1]}';
var signature = base64Url.encode(hmac.convert(data.codeUnits).bytes);
if (signature != split[2]) {
@ -102,9 +102,9 @@ class AuthToken {
String serialize(Hmac hmac) {
var headerString = base64Url.encode(json.encode(_header).codeUnits);
var payloadString = base64Url.encode(json.encode(toJson()).codeUnits);
var data = headerString + '.' + payloadString;
var data = '$headerString.$payloadString';
var signature = hmac.convert(data.codeUnits).bytes;
return data + '.' + base64Url.encode(signature);
return '$data.${base64Url.encode(signature)}';
}
Map<String, dynamic> toJson() {

View file

@ -39,7 +39,7 @@ class LocalAuthStrategy<User> extends AuthStrategy<User> {
@override
Future<User?> authenticate(RequestContext req, ResponseContext res,
[AngelAuthOptions? options]) async {
var _options = options ?? AngelAuthOptions();
var localOptions = options ?? AngelAuthOptions();
User? verificationResult;
if (allowBasic) {
@ -88,9 +88,9 @@ class LocalAuthStrategy<User> extends AuthStrategy<User> {
if (verificationResult == null ||
(verificationResult is Map && verificationResult.isEmpty)) {
if (_options.failureRedirect != null &&
_options.failureRedirect!.isNotEmpty) {
await res.redirect(_options.failureRedirect, code: 401);
if (localOptions.failureRedirect != null &&
localOptions.failureRedirect!.isNotEmpty) {
await res.redirect(localOptions.failureRedirect, code: 401);
return null;
}