From 2e46fc9772c35a3f4bc042b61d8941babbbaca24 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Wed, 30 Oct 2024 14:09:34 -0300 Subject: support bearer token for bank auth --- src/bank/mb_common.c | 13 +++++++++ src/bank/mb_parse.c | 54 +++++++++++++++++++++++++++++++++-- src/include/taler_merchant_bank_lib.h | 16 +++++++++++ 3 files changed, 81 insertions(+), 2 deletions(-) diff --git a/src/bank/mb_common.c b/src/bank/mb_common.c index d113ddf9..194be386 100644 --- a/src/bank/mb_common.c +++ b/src/bank/mb_common.c @@ -55,6 +55,19 @@ TALER_MERCHANT_BANK_setup_auth_ ( GNUNET_free (up); break; } + case TALER_MERCHANT_BANK_AUTH_BEARER: + { + if ( (CURLE_OK != + curl_easy_setopt (easy, + CURLOPT_HTTPAUTH, + CURLAUTH_BEARER)) || + (CURLE_OK != + curl_easy_setopt (easy, + CURLOPT_XOAUTH2_BEARER, + auth->details.bearer.token)) ) + ret = GNUNET_SYSERR; + break; + } } return ret; } diff --git a/src/bank/mb_parse.c b/src/bank/mb_parse.c index c05ea133..e4a1705f 100644 --- a/src/bank/mb_parse.c +++ b/src/bank/mb_parse.c @@ -32,8 +32,9 @@ static const struct const char *m; enum TALER_MERCHANT_BANK_AuthenticationMethod e; } methods[] = { - { "NONE", TALER_MERCHANT_BANK_AUTH_NONE }, - { "BASIC", TALER_MERCHANT_BANK_AUTH_BASIC }, + { "NONE", TALER_MERCHANT_BANK_AUTH_NONE }, + { "BASIC", TALER_MERCHANT_BANK_AUTH_BASIC }, + { "BEARER", TALER_MERCHANT_BANK_AUTH_BEARER }, { NULL, TALER_MERCHANT_BANK_AUTH_NONE } }; @@ -113,6 +114,23 @@ TALER_MERCHANT_BANK_auth_parse_cfg ( auth->method = TALER_MERCHANT_BANK_AUTH_BASIC; GNUNET_free (method); return GNUNET_OK; + case TALER_MERCHANT_BANK_AUTH_BEARER: + if (GNUNET_OK != + GNUNET_CONFIGURATION_get_value_string (cfg, + section, + "TOKEN", + &auth->details.bearer.token)) + { + GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, + section, + "TOKEN"); + GNUNET_free (method); + GNUNET_free (auth->wire_gateway_url); + return GNUNET_SYSERR; + } + auth->method = TALER_MERCHANT_BANK_AUTH_BEARER; + GNUNET_free (method); + return GNUNET_OK; } } } @@ -191,6 +209,35 @@ TALER_MERCHANT_BANK_auth_parse_json ( } auth->method = TALER_MERCHANT_BANK_AUTH_BASIC; return GNUNET_OK; + case TALER_MERCHANT_BANK_AUTH_BEARER: + { + const char *token; + struct GNUNET_JSON_Specification spec[] = { + GNUNET_JSON_spec_string ("token", + &token), + GNUNET_JSON_spec_end () + }; + enum GNUNET_GenericReturnValue res; + const char *err; + unsigned int eline; + + res = GNUNET_JSON_parse (cred, + spec, + &err, + &eline); + if (GNUNET_OK != res) + { + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "Credentials malformed: %s (%u)\n", + err, + eline); + GNUNET_free (auth->wire_gateway_url); + return GNUNET_SYSERR; + } + auth->details.bearer.token = GNUNET_strdup (token); + } + auth->method = TALER_MERCHANT_BANK_AUTH_BEARER; + return GNUNET_OK; } } } @@ -210,6 +257,9 @@ TALER_MERCHANT_BANK_auth_free ( GNUNET_free (auth->details.basic.username); GNUNET_free (auth->details.basic.password); break; + case TALER_MERCHANT_BANK_AUTH_BEARER: + GNUNET_free (auth->details.bearer.token); + break; } GNUNET_free (auth->wire_gateway_url); } diff --git a/src/include/taler_merchant_bank_lib.h b/src/include/taler_merchant_bank_lib.h index beaaa516..2971690a 100644 --- a/src/include/taler_merchant_bank_lib.h +++ b/src/include/taler_merchant_bank_lib.h @@ -43,6 +43,11 @@ enum TALER_MERCHANT_BANK_AuthenticationMethod * Basic authentication with cleartext username and password. */ TALER_MERCHANT_BANK_AUTH_BASIC, + + /** + * Bearer token authentication. + */ + TALER_MERCHANT_BANK_AUTH_BEARER, }; @@ -85,6 +90,17 @@ struct TALER_MERCHANT_BANK_AuthenticationData char *password; } basic; + /** + * Details for #TALER_MERCHANT_BANK_AUTH_BASIC. + */ + struct + { + /** + * Token to use. + */ + char *token; + } bearer; + } details; }; -- cgit v1.2.3