forceBasicAuth<User> function
Forces Basic authentication over the requested resource, with the given realm
name, if no JWT is present.
realm
defaults to 'angel3_auth'
.
Implementation
RequestHandler forceBasicAuth<User>({String? realm}) {
return (RequestContext req, ResponseContext res) async {
if (req.container != null) {
var reqContainer = req.container!;
if (reqContainer.has<User>()) {
return true;
} else if (reqContainer.has<Future<User>>()) {
await reqContainer.makeAsync<User>();
return true;
}
}
res.headers['www-authenticate'] = 'Basic realm="${realm ?? 'angel_auth'}"';
throw AngelHttpException.notAuthenticated();
};
}