#include "settings.h"
#include "oauth2.h"
#include "http-client.h"
+#include "http-url.h"
#include "iostream-ssl.h"
#include "auth-request.h"
#include "auth-settings.h"
const char *local_validation_key_dict;
/* valid token issuers */
const char *issuers;
+ /* The URL for a document following the OpenID Provider Configuration
+ Information schema, see
+
+ https://datatracker.ietf.org/doc/html/rfc7628#section-3.2.2
+ */
+ const char *openid_configuration_url;
/* TLS options */
const char *tls_ca_cert_file;
DEF_STR(client_id),
DEF_STR(client_secret),
DEF_STR(issuers),
+ DEF_STR(openid_configuration_url),
DEF_INT(timeout_msecs),
DEF_INT(max_idle_time_msecs),
DEF_INT(max_parallel_connections),
.client_id = "",
.client_secret = "",
.issuers = "",
+ .openid_configuration_url = "",
.pass_attrs = "",
.local_validation_key_dict = "",
.rawlog_dir = "",
db->oauth2_set.issuers = (const char *const *)
p_strsplit_spaces(pool, db->set.issuers, " ");
+ if (*db->set.openid_configuration_url != '\0') {
+ struct http_url *parsed_url ATTR_UNUSED;
+ if (http_url_parse(db->set.openid_configuration_url, NULL, 0,
+ pool_datastack_create(), &parsed_url,
+ &error) < 0) {
+ i_fatal("Invalid openid_configuration_url: %s",
+ error);
+ }
+ }
+
DLLIST_PREPEND(&db_oauth2_head, db);
return db;
pool_unref(&db->pool);
}
+static void
+db_oauth2_add_openid_config_url(struct db_oauth2_request *req)
+{
+ /* FIXME: HORRIBLE HACK - REMOVE ME!!!
+ It is because the mech has not been implemented properly
+ that we need to pass the config url in this strange way.
+
+ This **must** be moved to mech-oauth2 once the validation
+ result et al is handled there.
+ */
+ req->auth_request->openid_config_url =
+ p_strdup_empty(req->auth_request->pool,
+ req->db->set.openid_configuration_url);
+}
+
static bool
db_oauth2_have_all_fields(struct db_oauth2_request *req)
{
i_assert(result == PASSDB_RESULT_OK || error != NULL);
+ if (result != PASSDB_RESULT_OK)
+ db_oauth2_add_openid_config_url(req);
+
/* Successful lookups were logged by the caller. Failed lookups will be
logged either with e_error() or e_info() by the callback. */
if (callback != NULL) {
json_append_escaped(error, error_fields[i+1]);
str_append_c(error, '"');
}
+ /* FIXME: HORRIBLE HACK - REMOVE ME!!!
+ It is because the mech has not been implemented properly
+ that we need to pass the config url in this strange way.
+
+ This **must** be removed from here and db-oauth2 once the
+ validation result et al is handled here.
+ */
+ if (request->openid_config_url != NULL) {
+ if (str_len(error) > 0)
+ str_append_c(error, ',');
+ str_printfa(error, "\"openid-configuration\":\"");
+ json_append_escaped(error, request->openid_config_url);
+ str_append_c(error, '"');
+ }
str_append_c(error, '}');
auth_request_handler_reply_continue(request, str_data(error),
str_len(error));