challenger

OAuth 2.0-based authentication service that validates user can receive messages at a certain address
Log | Files | Refs | Submodules | README | LICENSE

pg_validation_get_pkce.c (3528B)


      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 challengerdb/pg_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 "pg_validation_get_pkce.h"
     27 #include "pg_helper.h"
     28 
     29 enum GNUNET_DB_QueryStatus
     30 CH_PG_validation_get_pkce (void *cls,
     31                       const struct CHALLENGER_ValidationNonceP *nonce,
     32                       char **client_secret,
     33                       json_t **address,
     34                       char **client_scope,
     35                       char **client_state,
     36                       char **client_redirect_uri,
     37                       char **code_challenge,
     38                       uint32_t *code_challenge_method)
     39 {
     40   struct PostgresClosure *pg = cls;
     41   struct GNUNET_PQ_QueryParam params[] = {
     42     GNUNET_PQ_query_param_auto_from_type (nonce),
     43     GNUNET_PQ_query_param_end
     44   };
     45   struct GNUNET_PQ_ResultSpec rs[] = {
     46     GNUNET_PQ_result_spec_string ("client_secret",
     47                                   client_secret),
     48     GNUNET_PQ_result_spec_allow_null (
     49       TALER_PQ_result_spec_json ("address",
     50                                  address),
     51       NULL),
     52     GNUNET_PQ_result_spec_allow_null (
     53       GNUNET_PQ_result_spec_string ("client_scope",
     54                                     client_scope),
     55       NULL),
     56     GNUNET_PQ_result_spec_allow_null (
     57       GNUNET_PQ_result_spec_string ("client_state",
     58                                     client_state),
     59       NULL),
     60     GNUNET_PQ_result_spec_string ("redirect_uri",
     61                                   client_redirect_uri),
     62     GNUNET_PQ_result_spec_allow_null (
     63       GNUNET_PQ_result_spec_string ("code_challenge",
     64                                     code_challenge),
     65       NULL),
     66     GNUNET_PQ_result_spec_allow_null (
     67       GNUNET_PQ_result_spec_uint32 ("code_challenge_method",
     68                                     code_challenge_method),
     69       NULL),
     70     GNUNET_PQ_result_spec_end
     71   };
     72 
     73   *client_scope = NULL;
     74   *client_state = NULL;
     75   *address = NULL;
     76   PREPARE (pg,
     77            "validation_get_pkce",
     78            "SELECT "
     79            "  client_secret"
     80            " ,address"
     81            " ,client_scope"
     82            " ,client_state"
     83            " ,COALESCE(client_redirect_uri,uri) AS redirect_uri"
     84            " ,code_challenge"
     85            " ,code_challenge_method"
     86            " FROM validations"
     87            " JOIN clients "
     88            "  USING (client_serial_id)"
     89            " WHERE nonce=$1");
     90   return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
     91                                                    "validation_get_pkce",
     92                                                    params,
     93                                                    rs);
     94 }