]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
auth: mech-oauth2 - Use the new lib-json
authorStephan Bosch <stephan.bosch@open-xchange.com>
Tue, 5 Oct 2021 00:42:55 +0000 (02:42 +0200)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Sat, 18 Nov 2023 18:58:04 +0000 (18:58 +0000)
src/auth/mech-oauth2.c

index b0da67cea8cb63bc003b6579c3e76c42a22ddf3d..b93d36298c560654c6f16927a534c01ab3321844 100644 (file)
@@ -6,7 +6,7 @@
 #include "mech.h"
 #include "passdb.h"
 #include "oauth2.h"
-#include "json-parser.h"
+#include "json-ostream.h"
 #include <ctype.h>
 
 struct oauth2_auth_request {
@@ -79,17 +79,16 @@ static void oauth2_verify_callback(enum passdb_result result,
                /* we could get new token after this */
                if (request->mech_password != NULL)
                        request->mech_password = NULL;
+
                string_t *error = t_str_new(64);
-               str_append_c(error, '{');
+               struct json_ostream *joutput =
+                       json_ostream_create_str(error, 0);
+
+               json_ostream_ndescend_object(joutput, NULL);
                for (unsigned int i = 0; error_fields[i] != NULL; i += 2) {
                        i_assert(error_fields[i+1] != NULL);
-                       if (i > 0)
-                               str_append_c(error, ',');
-                       str_append_c(error, '"');
-                       json_append_escaped(error, error_fields[i]);
-                       str_append(error, "\":\"");
-                       json_append_escaped(error, error_fields[i+1]);
-                       str_append_c(error, '"');
+                       json_ostream_nwrite_string(joutput, error_fields[i],
+                                                   error_fields[i+1]);
                }
                /* FIXME: HORRIBLE HACK - REMOVE ME!!!
                   It is because the mech has not been implemented properly
@@ -99,13 +98,12 @@ static void oauth2_verify_callback(enum passdb_result result,
                   validation result et al is handled here.
                */
                if (oauth2_find_oidc_url(request, &oidc_url)) {
-                       if (str_len(error) > 0)
-                               str_append_c(error, ',');
-                       str_printfa(error, "\"openid-configuration\":\"");
-                       json_append_escaped(error, oidc_url);
-                       str_append_c(error, '"');
+                       json_ostream_nwrite_string(
+                               joutput, "openid-configuration", oidc_url);
                }
-               str_append_c(error, '}');
+               json_ostream_nascend_object(joutput);
+               json_ostream_nfinish_destroy(&joutput);
+
                auth_request_fail_with_reply(request, str_data(error), str_len(error));
                break;
        }