merchant

Merchant backend to process payments, run by merchants
Log | Files | Refs | Submodules | README | LICENSE

commit a982cab1748401f96d714430dbbe7711818d3258
parent c1fdd363f635d944aa25ef338c5d6caf09b00213
Author: Martin Schanzenbach <schanzen@gnunet.org>
Date:   Mon, 24 Mar 2025 13:48:22 +0100

Rename "token" instance authentication method to "password" for clarity.
Renamed "token" key in token response to "access_token" for alignment
with Bank API

Diffstat:
Msrc/backend/taler-merchant-httpd_helper.c | 12++++++------
Msrc/backend/taler-merchant-httpd_private-get-instances-ID.c | 2+-
Msrc/backend/taler-merchant-httpd_private-post-instances-ID-token.c | 2+-
Msrc/lib/merchant_api_post_instance_auth.c | 10+++++-----
Msrc/lib/merchant_api_post_instances.c | 19+++++--------------
Msrc/testing/test_merchant_accounts.sh | 2+-
Msrc/testing/test_merchant_instance_auth.sh | 23+++++++++++++----------
Msrc/testing/test_merchant_instance_creation.sh | 4++--
Msrc/testing/test_merchant_instance_purge.sh | 2+-
Msrc/testing/test_merchant_instance_response.sh | 8++++----
Msrc/testing/testing_api_cmd_instance_token.c | 2+-
11 files changed, 40 insertions(+), 46 deletions(-)

diff --git a/src/backend/taler-merchant-httpd_helper.c b/src/backend/taler-merchant-httpd_helper.c @@ -596,13 +596,13 @@ TMH_check_token (const char *token, enum GNUNET_GenericReturnValue TMH_check_auth_config (struct MHD_Connection *connection, const json_t *jauth, - const char **auth_token) + const char **auth_password) { bool auth_wellformed = false; const char *auth_method = json_string_value (json_object_get (jauth, "method")); - *auth_token = NULL; + *auth_password = NULL; if (NULL == auth_method) { GNUNET_break_op (0); @@ -613,11 +613,11 @@ TMH_check_auth_config (struct MHD_Connection *connection, auth_wellformed = true; } else if (0 == strcmp (auth_method, - "token")) // FIXME "password" + "password")) { - *auth_token = json_string_value (json_object_get (jauth, - "token")); - if (NULL == *auth_token) + *auth_password = json_string_value (json_object_get (jauth, + "password")); + if (NULL == *auth_password) { GNUNET_break_op (0); } diff --git a/src/backend/taler-merchant-httpd_private-get-instances-ID.c b/src/backend/taler-merchant-httpd_private-get-instances-ID.c @@ -69,7 +69,7 @@ get_instances_ID (struct TMH_MerchantInstance *mi, GNUNET_JSON_pack_string ("method", GNUNET_is_zero (&mi->auth.auth_hash) ? "external" - : "token")); + : "password")); return TALER_MHD_REPLY_JSON_PACK ( connection, MHD_HTTP_OK, diff --git a/src/backend/taler-merchant-httpd_private-post-instances-ID-token.c b/src/backend/taler-merchant-httpd_private-post-instances-ID-token.c @@ -132,7 +132,7 @@ TMH_private_post_instances_ID_token (const struct TMH_RequestHandler *rh, ret = TALER_MHD_REPLY_JSON_PACK ( connection, MHD_HTTP_OK, - GNUNET_JSON_pack_string ("token", + GNUNET_JSON_pack_string ("access_token", tok), GNUNET_JSON_pack_string ("scope", scope), diff --git a/src/lib/merchant_api_post_instance_auth.c b/src/lib/merchant_api_post_instance_auth.c @@ -130,7 +130,7 @@ TALER_MERCHANT_instance_auth_post ( struct GNUNET_CURL_Context *ctx, const char *backend_url, const char *instance_id, - const char *auth_token, + const char *auth_password, TALER_MERCHANT_InstanceAuthPostCallback cb, void *cb_cls) { @@ -167,7 +167,7 @@ TALER_MERCHANT_instance_auth_post ( GNUNET_free (iaph); return NULL; } - if (NULL == auth_token) + if (NULL == auth_password) { req_obj = GNUNET_JSON_PACK ( GNUNET_JSON_pack_string ("method", @@ -177,9 +177,9 @@ TALER_MERCHANT_instance_auth_post ( { req_obj = GNUNET_JSON_PACK ( GNUNET_JSON_pack_string ("method", - "token"), - GNUNET_JSON_pack_string ("token", - auth_token)); + "password"), + GNUNET_JSON_pack_string ("password", + auth_password)); } GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Requesting URL '%s'\n", diff --git a/src/lib/merchant_api_post_instances.c b/src/lib/merchant_api_post_instances.c @@ -170,7 +170,7 @@ TALER_MERCHANT_instances_post ( bool use_stefan, struct GNUNET_TIME_Relative default_wire_transfer_delay, struct GNUNET_TIME_Relative default_pay_delay, - const char *auth_token, + const char *auth_password, TALER_MERCHANT_InstancesPostCallback cb, void *cb_cls) { @@ -178,22 +178,13 @@ TALER_MERCHANT_instances_post ( json_t *req_obj; json_t *auth_obj; - if (NULL != auth_token) + if (NULL != auth_password) { - if (0 != strncasecmp (RFC_8959_PREFIX, - auth_token, - strlen (RFC_8959_PREFIX))) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Authentication token must start with `%s'\n", - RFC_8959_PREFIX); - return NULL; - } auth_obj = GNUNET_JSON_PACK ( GNUNET_JSON_pack_string ("method", - "token"), - GNUNET_JSON_pack_string ("token", - auth_token)); + "password"), + GNUNET_JSON_pack_string ("password", + auth_password)); } else { diff --git a/src/testing/test_merchant_accounts.sh b/src/testing/test_merchant_accounts.sh @@ -41,7 +41,7 @@ echo -n "Configuring 'admin' instance ..." >&2 STATUS=$(curl -H "Content-Type: application/json" -X POST \ http://localhost:9966/management/instances \ - -d '{"auth":{"method":"token","token":"secret-token:new_value"},"id":"admin","name":"default","user_type":"business","address":{},"jurisdiction":{},"use_stefan":true,"default_wire_transfer_delay":{"d_us" : 3600000000},"default_pay_delay":{"d_us": 3600000000}}' \ + -d '{"auth":{"method":"password","password":"secret-token:new_value"},"id":"admin","name":"default","user_type":"business","address":{},"jurisdiction":{},"use_stefan":true,"default_wire_transfer_delay":{"d_us" : 3600000000},"default_pay_delay":{"d_us": 3600000000}}' \ -w "%{http_code}" -s -o /dev/null) if [ "$STATUS" != "204" ] diff --git a/src/testing/test_merchant_instance_auth.sh b/src/testing/test_merchant_instance_auth.sh @@ -41,7 +41,7 @@ echo -n "Configuring 'admin' instance ..." >&2 STATUS=$(curl -H "Content-Type: application/json" -X POST \ http://localhost:9966/management/instances \ - -d '{"auth":{"method":"token","token":"new_pw"},"id":"admin","name":"default","user_type":"business","address":{},"jurisdiction":{},"use_stefan":true,"default_wire_transfer_delay":{"d_us" : 3600000000},"default_pay_delay":{"d_us": 3600000000}}' \ + -d '{"auth":{"method":"password","password":"new_pw"},"id":"admin","name":"default","user_type":"business","address":{},"jurisdiction":{},"use_stefan":true,"default_wire_transfer_delay":{"d_us" : 3600000000},"default_pay_delay":{"d_us": 3600000000}}' \ -w "%{http_code}" -s -o /dev/null) if [ "$STATUS" != "204" ] @@ -49,6 +49,7 @@ then exit_fail "Expected 204, instance created. got: $STATUS" >&2 fi + BASIC_AUTH=$(echo -n default:new_pw | base64) STATUS=$(curl -H "Content-Type: application/json" -X POST \ @@ -63,7 +64,9 @@ then exit_fail "Expected 200 OK. Got: $STATUS" fi -TOKEN=$(jq -e -r .token < $LAST_RESPONSE) +TOKEN=$(jq -e -r .access_token < $LAST_RESPONSE) + +echo " OK" >&2 STATUS=$(curl -H "Content-Type: application/json" -X POST \ -H "Authorization: Bearer $TOKEN" \ @@ -142,7 +145,7 @@ then exit_fail "Expected 200 OK. Got: $STATUS" fi -TOKEN=$(jq -e -r .token < $LAST_RESPONSE) +TOKEN=$(jq -e -r .access_token < $LAST_RESPONSE) echo -n "Creating order to test auth is ok..." >&2 STATUS=$(curl -H "Content-Type: application/json" -X POST \ @@ -179,7 +182,7 @@ echo -n "Configuring 'second' instance ..." >&2 STATUS=$(curl -H "Content-Type: application/json" -X POST \ -H 'Authorization: Bearer '"$TOKEN" \ http://localhost:9966/management/instances \ - -d '{"auth":{"method":"token","token":"second"},"id":"second","name":"second","address":{},"jurisdiction":{},"use_stefan":true,"default_wire_transfer_delay":{"d_us" : 3600000000},"default_pay_delay":{"d_us": 3600000000}}' \ + -d '{"auth":{"method":"password","password":"second"},"id":"second","name":"second","address":{},"jurisdiction":{},"use_stefan":true,"default_wire_transfer_delay":{"d_us" : 3600000000},"default_pay_delay":{"d_us": 3600000000}}' \ -w "%{http_code}" -s -o /dev/null) if [ "$STATUS" != "204" ] @@ -194,7 +197,7 @@ echo -n "Configuring 'third' instance ..." >&2 STATUS=$(curl -H "Content-Type: application/json" -X POST \ -H 'Authorization: Bearer '"$TOKEN" \ http://localhost:9966/management/instances \ - -d '{"auth":{"method":"token","token":"third"},"id":"third","name":"third","address":{},"jurisdiction":{},"use_stefan":true,"default_wire_transfer_delay":{"d_us" : 3600000000},"default_pay_delay":{"d_us": 3600000000}}' \ + -d '{"auth":{"method":"password","password":"third"},"id":"third","name":"third","address":{},"jurisdiction":{},"use_stefan":true,"default_wire_transfer_delay":{"d_us" : 3600000000},"default_pay_delay":{"d_us": 3600000000}}' \ -w "%{http_code}" -s -o /dev/null) if [ "$STATUS" != "204" ] @@ -209,7 +212,7 @@ echo -n "Updating 'second' instance token using the 'new_one' auth token..." >&2 STATUS=$(curl -H "Content-Type: application/json" -X POST \ -H 'Authorization: Bearer '"$TOKEN" \ http://localhost:9966/management/instances/second/auth \ - -d '{"method":"token","token":"new_one"}' \ + -d '{"method":"password","password":"new_one"}' \ -w "%{http_code}" -s -o /dev/null) if [ "$STATUS" != "204" ] @@ -235,7 +238,7 @@ then exit_fail "Expected 200, login token created. got: $STATUS" fi -TOKEN=$(jq -e -r .token < "$LAST_RESPONSE") +TOKEN=$(jq -e -r .access_token < "$LAST_RESPONSE") echo " OK" >&2 @@ -253,7 +256,7 @@ then exit_fail "Expected 200, login token created. got: $STATUS" fi -RWTOKEN=$(jq -e -r .token < "$LAST_RESPONSE") +RWTOKEN=$(jq -e -r .access_token < "$LAST_RESPONSE") echo " OK" >&2 @@ -276,7 +279,7 @@ echo -n "Updating 'second' instance token using the 'second' auth token..." >&2 STATUS=$(curl -H "Content-Type: application/json" -X POST \ -H 'Authorization: Bearer '"$RWTOKEN" \ http://localhost:9966/instances/second/private/auth \ - -d '{"method":"token","token":"again"}' \ + -d '{"method":"password","password":"again"}' \ -w "%{http_code}" -s -o /dev/null) if [ "$STATUS" != "204" ] @@ -291,7 +294,7 @@ echo -n "Updating 'third' instance token using the 'second' auth token..." >&2 STATUS=$(curl -H "Content-Type: application/json" -X POST \ -H 'Authorization: Bearer '"$RWTOKEN" \ http://localhost:9966/management/instances/third/auth \ - -d '{"method":"token","token":"new_one"}' \ + -d '{"method":"password","password":"new_one"}' \ -w "%{http_code}" -s -o /dev/null) if [ "$STATUS" != "401" ] diff --git a/src/testing/test_merchant_instance_creation.sh b/src/testing/test_merchant_instance_creation.sh @@ -27,7 +27,7 @@ echo -n "Configuring a merchant instance before configuring the admin instance . STATUS=$(curl -H "Content-Type: application/json" -X POST \ http://localhost:9966/management/instances \ - -d '{"auth":{"method":"token","token":"secret-token:other_secret"},"id":"first","name":"test","address":{},"jurisdiction":{},"use_stefan":true,"default_wire_transfer_delay":{"d_us" : 3600000000},"default_pay_delay":{"d_us": 3600000000}}' \ + -d '{"auth":{"method":"password","password":"secret-token:other_secret"},"id":"first","name":"test","address":{},"jurisdiction":{},"use_stefan":true,"default_wire_transfer_delay":{"d_us" : 3600000000},"default_pay_delay":{"d_us": 3600000000}}' \ -w "%{http_code}" -s -o /dev/null) if [ "$STATUS" != "204" ] @@ -58,7 +58,7 @@ echo -n "Configuring a second merchant instance ..." STATUS=$(curl -H "Content-Type: application/json" -X POST \ http://localhost:9966/management/instances \ - -d '{"auth":{"method":"token","token":"secret-token:other_secret"},"id":"second","name":"test","address":{},"jurisdiction":{},"use_stefan":true,"default_wire_transfer_delay":{"d_us" : 3600000000},"default_pay_delay":{"d_us": 3600000000}}' \ + -d '{"auth":{"method":"password","password":"secret-token:other_secret"},"id":"second","name":"test","address":{},"jurisdiction":{},"use_stefan":true,"default_wire_transfer_delay":{"d_us" : 3600000000},"default_pay_delay":{"d_us": 3600000000}}' \ -w "%{http_code}" -s -o /dev/null) if [ "$STATUS" != "401" ] diff --git a/src/testing/test_merchant_instance_purge.sh b/src/testing/test_merchant_instance_purge.sh @@ -42,7 +42,7 @@ echo -n "Configuring merchant instance ..." >&2 STATUS=$(curl -H "Content-Type: application/json" -X POST \ http://localhost:9966/management/instances \ - -d '{"auth":{"method":"token","token":"secret-token:other_secret"},"id":"test","name":"test","address":{},"jurisdiction":{},"use_stefan":true,"default_wire_transfer_delay":{"d_us" : 3600000000},"default_pay_delay":{"d_us": 3600000000}}' \ + -d '{"auth":{"method":"password","password":"secret-token:other_secret"},"id":"test","name":"test","address":{},"jurisdiction":{},"use_stefan":true,"default_wire_transfer_delay":{"d_us" : 3600000000},"default_pay_delay":{"d_us": 3600000000}}' \ -w "%{http_code}" -s -o /dev/null) if [ "$STATUS" != "204" ] diff --git a/src/testing/test_merchant_instance_response.sh b/src/testing/test_merchant_instance_response.sh @@ -44,7 +44,7 @@ fi STATUS=$(curl -H "Content-Type: application/json" -X POST \ http://localhost:9966/management/instances \ - -d '{"auth":{"method":"token","token":"other_secret"},"id":"default","admin":"default","user_type":"business","address":{},"jurisdiction":{},"use_stefan":true,"default_wire_transfer_delay":{"d_us" : 3600000000},"default_pay_delay":{"d_us": 3600000000}}' \ + -d '{"auth":{"method":"password","password":"other_secret"},"id":"admin","name":"default","user_type":"business","address":{},"jurisdiction":{},"use_stefan":true,"default_wire_transfer_delay":{"d_us" : 3600000000},"default_pay_delay":{"d_us": 3600000000}}' \ -w "%{http_code}" -s -o /dev/null) if [ "$STATUS" != "204" ] @@ -75,7 +75,7 @@ then exit_fail "Expected 200 OK. Got: $STATUS" fi -TOKEN=$(jq -e -r .token < $LAST_RESPONSE) +TOKEN=$(jq -e -r .access_token < $LAST_RESPONSE) STATUS=$(curl -H "Content-Type: application/json" -X GET \ -H "Authorization: Bearer $TOKEN" \ @@ -90,7 +90,7 @@ fi STATUS=$(curl -H "Content-Type: application/json" -X POST \ -H "Authorization: Bearer $TOKEN" \ http://localhost:9966/private/auth \ - -d '{"method":"token","token":"zxc"}' \ + -d '{"method":"password","password":"zxc"}' \ -w "%{http_code}" -s -o /dev/null) if [ "$STATUS" != "204" ] @@ -139,7 +139,7 @@ then exit_fail "Expected 200 OK. Got: $STATUS" fi -TOKEN=$(jq -e -r .token < $LAST_RESPONSE) +TOKEN=$(jq -e -r .access_token < $LAST_RESPONSE) STATUS=$(curl -H "Content-Type: application/json" -X DELETE \ -H "Authorization: Bearer $TOKEN" \ diff --git a/src/testing/testing_api_cmd_instance_token.c b/src/testing/testing_api_cmd_instance_token.c @@ -129,7 +129,7 @@ token_instance_cb (void *cls, GNUNET_assert (GNUNET_NO == tis->is_delete); /* Get token */ struct GNUNET_JSON_Specification spec[] = { - GNUNET_JSON_spec_string_copy ("token", + GNUNET_JSON_spec_string_copy ("access_token", &tis->token), GNUNET_JSON_spec_string ("scope", &scope),