]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
auth: db-oauth2 - Add token parameter to db_oauth2_local_validation
authorAki Tuomi <aki.tuomi@open-xchange.com>
Tue, 26 May 2020 09:12:32 +0000 (12:12 +0300)
committerAki Tuomi <aki.tuomi@open-xchange.com>
Wed, 27 May 2020 07:51:31 +0000 (10:51 +0300)
src/auth/db-oauth2.c

index 4c3af9742fae6b127d31697a5cad1de1efa188e9..91ed1343e9359016b6555879e8c52dcc3f5dc16c 100644 (file)
@@ -632,24 +632,22 @@ static void db_oauth2_lookup_introspect(struct db_oauth2_request *req)
                                              db_oauth2_introspect_continue, req);
 }
 
-static int db_oauth2_local_validation(struct db_oauth2_request *req)
+static void db_oauth2_local_validation(struct db_oauth2_request *req,
+                                      const char *token)
 {
-       bool is_jwt;
+       bool is_jwt ATTR_UNUSED;
        const char *error = NULL;
        enum passdb_result passdb_result;
        ARRAY_TYPE(oauth2_field) fields;
        t_array_init(&fields, 8);
-       if (oauth2_try_parse_jwt(&req->db->oauth2_set, req->auth_request->mech_password,
+       if (oauth2_try_parse_jwt(&req->db->oauth2_set, token,
                                 &fields, &is_jwt, &error) < 0) {
-               if (!is_jwt)
-                       return -1;
                passdb_result = PASSDB_RESULT_PASSWORD_MISMATCH;
        } else {
                db_oauth2_fields_merge(req, &fields);
                db_oauth2_process_fields(req, &passdb_result, &error);
        }
        db_oauth2_callback(req, passdb_result, error);
-       return 0;
 }
 
 static void
@@ -761,10 +759,7 @@ void db_oauth2_lookup(struct db_oauth2 *db, struct db_oauth2_request *req,
                /* try to validate token locally */
                e_debug(authdb_event(req->auth_request),
                        "oauth2: Attempting to locally validate token");
-               /* will send result if ret = 0 */
-               if (db_oauth2_local_validation(req) < 0)
-                       db_oauth2_callback(req, PASSDB_RESULT_PASSWORD_MISMATCH,
-                                          "oauth2: Not a JWT token");
+               db_oauth2_local_validation(req, request->mech_password);
                return;
 
        }