From a29700f26d01fe1e6ed138e2ea5a8e6d5810054f Mon Sep 17 00:00:00 2001 From: Joris Vink Date: Mon, 31 Jan 2022 15:13:34 +0100 Subject: [PATCH] Bring back page authentication via config. Inside of the new route handlers the "authenticate" keyword can be specified to let the route authenticate via a previously configured authentication block. The ability to do this went missing in a previous commit that overhauled the routing structure of the configuration. --- src/config.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/config.c b/src/config.c index 6062b9f..bda2109 100644 --- a/src/config.c +++ b/src/config.c @@ -113,6 +113,7 @@ static int configure_route_methods(char *); static int configure_route_handler(char *); static int configure_route_on_free(char *); static int configure_route_on_headers(char *); +static int configure_route_authenticate(char *); static int configure_route_on_body_chunk(char *); static int configure_filemap(char *); static int configure_return(char *); @@ -204,6 +205,7 @@ static struct { { "on_body_chunk", configure_route_on_body_chunk }, { "on_free", configure_route_on_free }, { "methods", configure_route_methods }, + { "authenticate", configure_route_authenticate }, { "filemap", configure_filemap }, { "redirect", configure_redirect }, { "return", configure_return }, @@ -1223,6 +1225,26 @@ configure_route_on_free(char *name) return (KORE_RESULT_OK); } +static int +configure_route_authenticate(char *name) +{ + if (current_route == NULL) { + kore_log(LOG_ERR, + "authenticate keyword not inside of route context"); + return (KORE_RESULT_ERROR); + } + + current_route->auth = kore_auth_lookup(name); + + if (current_route->auth == NULL) { + kore_log(LOG_ERR, "no such authentication '%s' for '%s' found", + name, current_route->path); + return (KORE_RESULT_ERROR); + } + + return (KORE_RESULT_OK); +} + static int configure_route_methods(char *options) {