diff options
author | Sebastian <sebasjm@gmail.com> | 2024-10-30 14:09:34 -0300 |
---|---|---|
committer | Sebastian <sebasjm@gmail.com> | 2024-10-30 14:09:34 -0300 |
commit | 2e46fc9772c35a3f4bc042b61d8941babbbaca24 (patch) | |
tree | 73cff76f665b823465f488a29ce37bd6dbabd805 /src/bank | |
parent | 1e015377f88bfe6208987145a05ba6cbe78e0597 (diff) |
support bearer token for bank auth
Diffstat (limited to 'src/bank')
-rw-r--r-- | src/bank/mb_common.c | 13 | ||||
-rw-r--r-- | src/bank/mb_parse.c | 54 |
2 files changed, 65 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); } |