validation_get_pkce.c (3584B)
1 /* 2 This file is part of Challenger 3 Copyright (C) 2023 Taler Systems SA 4 5 Challenger 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 Challenger 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 Challenger; see the file COPYING. If not, see <http://www.gnu.org/licenses/> 15 */ 16 /** 17 * @file src/challengerdb/validation_get_pkce.c 18 * @brief Implementation of the validation_get_pkce function for Postgres 19 * @author Bohdan Potuzhnyi 20 * @author Vlada Svirsh 21 */ 22 #include "platform.h" 23 #include <taler/taler_error_codes.h> 24 #include <taler/taler_dbevents.h> 25 #include <taler/taler_pq_lib.h> 26 #include "validation_get_pkce.h" 27 #include "pg_helper.h" 28 29 enum GNUNET_DB_QueryStatus 30 CHALLENGERDB_validation_get_pkce ( 31 struct CHALLENGERDB_PostgresContext *ctx, 32 const struct CHALLENGER_ValidationNonceP *nonce, 33 uint64_t client_id, 34 char **client_secret, 35 json_t **address, 36 char **client_scope, 37 char **client_state, 38 char **client_redirect_uri, 39 char **code_challenge, 40 uint32_t *code_challenge_method) 41 { 42 struct GNUNET_TIME_Absolute now 43 = GNUNET_TIME_absolute_get (); 44 struct GNUNET_PQ_QueryParam params[] = { 45 GNUNET_PQ_query_param_auto_from_type (nonce), 46 GNUNET_PQ_query_param_absolute_time (&now), 47 GNUNET_PQ_query_param_uint64 (&client_id), 48 GNUNET_PQ_query_param_end 49 }; 50 struct GNUNET_PQ_ResultSpec rs[] = { 51 GNUNET_PQ_result_spec_string ("client_secret", 52 client_secret), 53 GNUNET_PQ_result_spec_allow_null ( 54 TALER_PQ_result_spec_json ("address", 55 address), 56 NULL), 57 GNUNET_PQ_result_spec_allow_null ( 58 GNUNET_PQ_result_spec_string ("client_scope", 59 client_scope), 60 NULL), 61 GNUNET_PQ_result_spec_allow_null ( 62 GNUNET_PQ_result_spec_string ("client_state", 63 client_state), 64 NULL), 65 GNUNET_PQ_result_spec_string ("redirect_uri", 66 client_redirect_uri), 67 GNUNET_PQ_result_spec_allow_null ( 68 GNUNET_PQ_result_spec_string ("code_challenge", 69 code_challenge), 70 NULL), 71 GNUNET_PQ_result_spec_uint32 ("code_challenge_method", 72 code_challenge_method), 73 GNUNET_PQ_result_spec_end 74 }; 75 76 *client_scope = NULL; 77 *client_state = NULL; 78 *address = NULL; 79 PREPARE (ctx, 80 "validation_get_pkce", 81 "SELECT " 82 " client_secret" 83 " ,address" 84 " ,client_scope" 85 " ,client_state" 86 " ,COALESCE(client_redirect_uri,uri) AS redirect_uri" 87 " ,code_challenge" 88 " ,code_challenge_method" 89 " FROM validations" 90 " JOIN clients " 91 " USING (client_serial_id)" 92 " WHERE nonce=$1" 93 " AND expiration_time > $2" 94 " AND client_serial_id=$3"); 95 return GNUNET_PQ_eval_prepared_singleton_select (ctx->conn, 96 "validation_get_pkce", 97 params, 98 rs); 99 }