challenger

OAuth 2.0-based authentication service that validates user can receive messages at a certain address
Log | Files | Refs | Submodules | README | LICENSE

commit 324e6d5575c33af15fe368165407b6292b696df0
parent 9e02e59010fd6a0192e8ad547217189f1beba72e
Author: Sebastian <sebasjm@gmail.com>
Date:   Wed,  3 Jul 2024 15:35:51 -0300

reply with SPA on authorize request

Diffstat:
Msrc/challenger/challenger-httpd.c | 1-
Msrc/challenger/challenger-httpd_authorize.c | 67+++++++++++++++++++++++++++++++++----------------------------------
2 files changed, 33 insertions(+), 35 deletions(-)

diff --git a/src/challenger/challenger-httpd.c b/src/challenger/challenger-httpd.c @@ -35,7 +35,6 @@ #include "challenger-httpd_token.h" #include "challenger-httpd_spa.h" #include "challenger_database_lib.h" -#include <taler/taler_templating_lib.h> /** diff --git a/src/challenger/challenger-httpd_authorize.c b/src/challenger/challenger-httpd_authorize.c @@ -24,6 +24,7 @@ #include <taler/taler_templating_lib.h> #include "challenger-httpd_authorize.h" #include "challenger-httpd_common.h" +#include "challenger-httpd_spa.h" /** @@ -232,17 +233,37 @@ CH_handler_authorize (struct CH_HandlerContext *hc, case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT: break; } + if (0 == CH_get_output_type (hc->connection)) + { + const char *prev_full_url = hc->full_url; + + const char *rparams = strchr (hc->full_url, '?'); + if (NULL == rparams) + GNUNET_asprintf (&hc->full_url, + "%s?nonce=%s", + prev_full_url, + hc->path); + + else + GNUNET_asprintf (&hc->full_url, + "%s&nonce=%s", + prev_full_url, + hc->path); + + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Redirect before %s now `%s'\n", + prev_full_url, + hc->full_url); + + GNUNET_free (prev_full_url); + return CH_spa_redirect (hc, NULL, 0); + } { enum GNUNET_GenericReturnValue ret; json_t *args; - char *form; struct MHD_Response *resp; - unsigned int http_status; MHD_RESULT res; - GNUNET_asprintf (&form, - "enter-%s-form", - CH_address_type); args = GNUNET_JSON_PACK ( GNUNET_JSON_pack_bool ("fix_address", 0 == address_attempts_left), @@ -256,46 +277,24 @@ CH_handler_authorize (struct CH_HandlerContext *hc, GNUNET_JSON_pack_uint64 ("auth_attempts_left", auth_attempts_left), GNUNET_JSON_pack_timestamp ("retransmission_time", - GNUNET_TIME_absolute_to_timestamp( + GNUNET_TIME_absolute_to_timestamp ( GNUNET_TIME_absolute_add ( last_tx_time, CH_validation_duration))), GNUNET_JSON_pack_uint64 ("changes_left", address_attempts_left) ); - http_status = MHD_HTTP_OK; - if (0 == CH_get_output_type (hc->connection)) - { - ret = TALER_TEMPLATING_build ( - hc->connection, - &http_status, - form, - NULL, - NULL, - args, - &resp); - GNUNET_free (form); - json_decref (args); - if (GNUNET_SYSERR == ret) - { - GNUNET_break (0); - return MHD_NO; - } - GNUNET_break (GNUNET_OK == ret); - } - else - { - GNUNET_break (0 == - json_object_del (args, - "nonce")); - resp = TALER_MHD_make_json_steal (args); - } + + GNUNET_break (0 == + json_object_del (args, + "nonce")); + resp = TALER_MHD_make_json_steal (args); GNUNET_break (MHD_YES == MHD_add_response_header (resp, MHD_HTTP_HEADER_CACHE_CONTROL, "no-store,no-cache")); res = MHD_queue_response (hc->connection, - http_status, + MHD_HTTP_OK, resp); MHD_destroy_response (resp); return res;