challenger

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

validation_get_pkce.c (3475B)


      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   char **client_secret,
     34   json_t **address,
     35   char **client_scope,
     36   char **client_state,
     37   char **client_redirect_uri,
     38   char **code_challenge,
     39   uint32_t *code_challenge_method)
     40 {
     41   struct GNUNET_TIME_Absolute now
     42     = GNUNET_TIME_absolute_get ();
     43   struct GNUNET_PQ_QueryParam params[] = {
     44     GNUNET_PQ_query_param_auto_from_type (nonce),
     45     GNUNET_PQ_query_param_absolute_time (&now),
     46     GNUNET_PQ_query_param_end
     47   };
     48   struct GNUNET_PQ_ResultSpec rs[] = {
     49     GNUNET_PQ_result_spec_string ("client_secret",
     50                                   client_secret),
     51     GNUNET_PQ_result_spec_allow_null (
     52       TALER_PQ_result_spec_json ("address",
     53                                  address),
     54       NULL),
     55     GNUNET_PQ_result_spec_allow_null (
     56       GNUNET_PQ_result_spec_string ("client_scope",
     57                                     client_scope),
     58       NULL),
     59     GNUNET_PQ_result_spec_allow_null (
     60       GNUNET_PQ_result_spec_string ("client_state",
     61                                     client_state),
     62       NULL),
     63     GNUNET_PQ_result_spec_string ("redirect_uri",
     64                                   client_redirect_uri),
     65     GNUNET_PQ_result_spec_allow_null (
     66       GNUNET_PQ_result_spec_string ("code_challenge",
     67                                     code_challenge),
     68       NULL),
     69     GNUNET_PQ_result_spec_uint32 ("code_challenge_method",
     70                                   code_challenge_method),
     71     GNUNET_PQ_result_spec_end
     72   };
     73 
     74   *client_scope = NULL;
     75   *client_state = NULL;
     76   *address = NULL;
     77   PREPARE (ctx,
     78            "validation_get_pkce",
     79            "SELECT "
     80            "  client_secret"
     81            " ,address"
     82            " ,client_scope"
     83            " ,client_state"
     84            " ,COALESCE(client_redirect_uri,uri) AS redirect_uri"
     85            " ,code_challenge"
     86            " ,code_challenge_method"
     87            " FROM validations"
     88            " JOIN clients "
     89            "  USING (client_serial_id)"
     90            " WHERE nonce=$1"
     91            "   AND expiration_time > $2");
     92   return GNUNET_PQ_eval_prepared_singleton_select (ctx->conn,
     93                                                    "validation_get_pkce",
     94                                                    params,
     95                                                    rs);
     96 }