mb_common.c (2215B)
1 /* 2 This file is part of Taler 3 Copyright (C) 2015-2023 Taler Systems SA 4 5 Taler is free software; you can redistribute it and/or modify it under the 6 terms of the GNU General Public License as published by the Free Software 7 Foundation; either version 3, or (at your option) any later version. 8 9 Taler is distributed in the hope that it will be useful, but WITHOUT ANY 10 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 11 A PARTICULAR PURPOSE. See the GNU General Public License for more details. 12 13 You should have received a copy of the GNU General Public License along with 14 Taler; see the file COPYING. If not, see 15 <http://www.gnu.org/licenses/> 16 */ 17 /** 18 * @file bank/mb_common.c 19 * @brief Common functions for the bank API 20 * @author Christian Grothoff 21 */ 22 #include "platform.h" 23 #include "mb_common.h" 24 25 26 enum GNUNET_GenericReturnValue 27 TALER_MERCHANT_BANK_setup_auth_ ( 28 CURL *easy, 29 const struct TALER_MERCHANT_BANK_AuthenticationData *auth) 30 { 31 enum GNUNET_GenericReturnValue ret; 32 33 ret = GNUNET_OK; 34 switch (auth->method) 35 { 36 case TALER_MERCHANT_BANK_AUTH_NONE: 37 return GNUNET_OK; 38 case TALER_MERCHANT_BANK_AUTH_BASIC: 39 { 40 char *up; 41 42 GNUNET_asprintf (&up, 43 "%s:%s", 44 auth->details.basic.username, 45 auth->details.basic.password); 46 if ( (CURLE_OK != 47 curl_easy_setopt (easy, 48 CURLOPT_HTTPAUTH, 49 CURLAUTH_BASIC)) || 50 (CURLE_OK != 51 curl_easy_setopt (easy, 52 CURLOPT_USERPWD, 53 up)) ) 54 ret = GNUNET_SYSERR; 55 GNUNET_free (up); 56 break; 57 } 58 case TALER_MERCHANT_BANK_AUTH_BEARER: 59 { 60 if ( (CURLE_OK != 61 curl_easy_setopt (easy, 62 CURLOPT_HTTPAUTH, 63 CURLAUTH_BEARER)) || 64 (CURLE_OK != 65 curl_easy_setopt (easy, 66 CURLOPT_XOAUTH2_BEARER, 67 auth->details.bearer.token)) ) 68 ret = GNUNET_SYSERR; 69 break; 70 } 71 } 72 return ret; 73 } 74 75 76 /* end of mb_common.c */