aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian <sebasjm@gmail.com>2024-10-30 14:09:34 -0300
committerSebastian <sebasjm@gmail.com>2024-10-30 14:09:34 -0300
commit2e46fc9772c35a3f4bc042b61d8941babbbaca24 (patch)
tree73cff76f665b823465f488a29ce37bd6dbabd805
parent1e015377f88bfe6208987145a05ba6cbe78e0597 (diff)
support bearer token for bank auth
-rw-r--r--src/bank/mb_common.c13
-rw-r--r--src/bank/mb_parse.c54
-rw-r--r--src/include/taler_merchant_bank_lib.h16
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;
};