commit 7b365a122fdffec83c2cf7bd969bd3263c387e59
parent 93810883d000ecb01f2db4bd33a643dc5d150e9c
Author: Christian Grothoff <christian@grothoff.org>
Date: Sat, 28 Mar 2026 22:28:40 +0100
make setting password an option for the /auth request
Diffstat:
3 files changed, 128 insertions(+), 9 deletions(-)
diff --git a/src/include/taler/taler-merchant/post-management-instances-INSTANCE-auth.h b/src/include/taler/taler-merchant/post-management-instances-INSTANCE-auth.h
@@ -57,6 +57,65 @@ struct TALER_MERCHANT_PostManagementInstancesAuthResponse
/**
+ * Options for POST /management/instances/$INSTANCE/auth.
+ */
+enum TALER_MERCHANT_PostManagementInstancesAuthOption
+{
+ /**
+ * Sentinel value, end of options.
+ */
+ TALER_MERCHANT_POST_MANAGEMENT_INSTANCES_AUTH_OPTION_END = 0,
+
+ /**
+ * Set the authentication password. If not set (or set to NULL),
+ * the "external" authentication method is used.
+ * Value type: const char *.
+ */
+ TALER_MERCHANT_POST_MANAGEMENT_INSTANCES_AUTH_OPTION_PASSWORD
+};
+
+
+/**
+ * Value for a POST /management/instances/$INSTANCE/auth option.
+ */
+struct TALER_MERCHANT_PostManagementInstancesAuthOptionValue
+{
+ /**
+ * Which option is being set.
+ */
+ enum TALER_MERCHANT_PostManagementInstancesAuthOption option;
+
+ /**
+ * Specific option value.
+ */
+ union
+ {
+
+ /**
+ * Value if @e option is
+ * #TALER_MERCHANT_POST_MANAGEMENT_INSTANCES_AUTH_OPTION_PASSWORD.
+ */
+ const char *password;
+
+ } details;
+};
+
+
+/**
+ * Set password.
+ *
+ * @param pw password to set
+ * @return representation of the option
+ */
+#define TALER_MERCHANT_post_management_instances_auth_option_password(pw) \
+ (const struct TALER_MERCHANT_PostManagementInstancesAuthOptionValue) \
+ { \
+ .option = TALER_MERCHANT_POST_MANAGEMENT_INSTANCES_AUTH_OPTION_PASSWORD, \
+ .details.password = (pw) \
+ }
+
+
+/**
* Set up POST /management/instances/$INSTANCE/auth operation.
* Note that you must explicitly start the operation after
* possibly setting options.
@@ -64,15 +123,53 @@ struct TALER_MERCHANT_PostManagementInstancesAuthResponse
* @param ctx the context
* @param url base URL of the merchant backend
* @param instance_id identifier of the instance
- * @param auth_password new authentication password
* @return handle to operation
*/
struct TALER_MERCHANT_PostManagementInstancesAuthHandle *
TALER_MERCHANT_post_management_instances_auth_create (
struct GNUNET_CURL_Context *ctx,
const char *url,
- const char *instance_id,
- const char *auth_password); // FIXME: make password an option!
+ const char *instance_id);
+
+
+/**
+ * Set options for POST /management/instances/$INSTANCE/auth operation.
+ *
+ * @param[in,out] piah the handle to set options for
+ * @param num_options length of the @a options array
+ * @param options array of option values (terminated with _END)
+ */
+void
+TALER_MERCHANT_post_management_instances_auth_set_options_ (
+ struct TALER_MERCHANT_PostManagementInstancesAuthHandle *piah,
+ unsigned int num_options,
+ const struct TALER_MERCHANT_PostManagementInstancesAuthOptionValue options[]);
+
+
+/**
+ * Maximum number of options for set_options macro.
+ */
+#define TALER_MERCHANT_POST_MANAGEMENT_INSTANCES_AUTH_OPTIONS_ARRAY_MAX_SIZE 4
+
+/**
+ * Set options for POST /management/instances/$INSTANCE/auth operation.
+ * Variadic macro wrapper around
+ * #TALER_MERCHANT_post_management_instances_auth_set_options_().
+ *
+ * @param piah the handle to set options for
+ * @param ... option values (automatically terminated with _END)
+ */
+#define TALER_MERCHANT_post_management_instances_auth_set_options(piah, ...) \
+ do { \
+ struct TALER_MERCHANT_PostManagementInstancesAuthOptionValue __opts[] = { \
+ __VA_ARGS__, \
+ { .option = TALER_MERCHANT_POST_MANAGEMENT_INSTANCES_AUTH_OPTION_END } \
+ }; \
+ TALER_MERCHANT_post_management_instances_auth_set_options_ ( \
+ piah, \
+ sizeof (__opts) / sizeof (__opts[0]) - 1, \
+ __opts); \
+ } while (0)
#ifndef TALER_MERCHANT_POST_MANAGEMENT_INSTANCES_AUTH_RESULT_CLOSURE
diff --git a/src/lib/merchant_api_post-management-instances-INSTANCE-auth.c b/src/lib/merchant_api_post-management-instances-INSTANCE-auth.c
@@ -154,8 +154,7 @@ struct TALER_MERCHANT_PostManagementInstancesAuthHandle *
TALER_MERCHANT_post_management_instances_auth_create (
struct GNUNET_CURL_Context *ctx,
const char *url,
- const char *instance_id,
- const char *auth_password)
+ const char *instance_id)
{
struct TALER_MERCHANT_PostManagementInstancesAuthHandle *piah;
@@ -164,12 +163,33 @@ TALER_MERCHANT_post_management_instances_auth_create (
piah->base_url = GNUNET_strdup (url);
if (NULL != instance_id)
piah->instance_id = GNUNET_strdup (instance_id);
- if (NULL != auth_password)
- piah->auth_password = GNUNET_strdup (auth_password);
return piah;
}
+void
+TALER_MERCHANT_post_management_instances_auth_set_options_ (
+ struct TALER_MERCHANT_PostManagementInstancesAuthHandle *piah,
+ unsigned int num_options,
+ const struct TALER_MERCHANT_PostManagementInstancesAuthOptionValue options[])
+{
+ for (unsigned int i = 0; i < num_options; i++)
+ {
+ switch (options[i].option)
+ {
+ case TALER_MERCHANT_POST_MANAGEMENT_INSTANCES_AUTH_OPTION_END:
+ return;
+ case TALER_MERCHANT_POST_MANAGEMENT_INSTANCES_AUTH_OPTION_PASSWORD:
+ GNUNET_free (piah->auth_password);
+ if (NULL != options[i].details.password)
+ piah->auth_password = GNUNET_strdup (
+ options[i].details.password);
+ break;
+ }
+ }
+}
+
+
enum TALER_ErrorCode
TALER_MERCHANT_post_management_instances_auth_start (
struct TALER_MERCHANT_PostManagementInstancesAuthHandle *piah,
diff --git a/src/testing/testing_api_cmd_instance_auth.c b/src/testing/testing_api_cmd_instance_auth.c
@@ -130,8 +130,10 @@ auth_instance_run (void *cls,
ais->iaph = TALER_MERCHANT_post_management_instances_auth_create (
TALER_TESTING_interpreter_get_context (is),
ais->merchant_url,
- ais->instance_id,
- ais->auth_token);
+ ais->instance_id);
+ TALER_MERCHANT_post_management_instances_auth_set_options (
+ ais->iaph,
+ TALER_MERCHANT_post_management_instances_auth_option_password (ais->auth_token));
{
enum TALER_ErrorCode ec;