]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
auth: Add caching to passdb-oauth.
authorSergey Kitov <sergey.kitov@open-xchange.com>
Thu, 14 Feb 2019 14:03:02 +0000 (16:03 +0200)
committerVille Savolainen <ville.savolainen@dovecot.fi>
Thu, 21 Mar 2019 08:02:53 +0000 (10:02 +0200)
src/auth/db-oauth2.c
src/auth/db-oauth2.h
src/auth/passdb-oauth2.c

index ad9a54760547d1ed65e1df6e233bdccefbecd58b..b3ababb11de0b733ca481a9c1e80dfa1a6d754ba 100644 (file)
@@ -702,3 +702,8 @@ void db_oauth2_lookup(struct db_oauth2 *db, struct db_oauth2_request *req,
        }
        DLLIST_PREPEND(&db->head, req);
 }
+
+bool db_oauth2_uses_password_grant(const struct db_oauth2 *db)
+{
+       return db->set.use_grant_password;
+}
index 2b46fbfc7c85c0b41a7f46a8aa742cd5ec6180bd..9386b70fd15976e7da337ef591b96d89ae86e277 100644 (file)
@@ -35,6 +35,8 @@ struct db_oauth2 *db_oauth2_init(const char *config_path);
 void db_oauth2_ref(struct db_oauth2 *);
 void db_oauth2_unref(struct db_oauth2 **);
 
+bool db_oauth2_uses_password_grant(const struct db_oauth2 *db);
+
 void db_oauth2_lookup(struct db_oauth2 *db, struct db_oauth2_request *req, const char *token, struct auth_request *request, db_oauth2_lookup_callback_t *callback, void *context);
 #define db_oauth2_lookup(db, req, token, request, callback, context) \
        db_oauth2_lookup(db, req, token + \
index 2c2f558bc5d81d7762d62095a5502ce2f3356185..7ba75d4aa17a32b807cc0916d5edef60814e6897 100644 (file)
@@ -20,6 +20,9 @@ oauth2_verify_plain_continue(struct db_oauth2_request *req,
        else if (result != PASSDB_RESULT_OK)
                auth_request_log_info(request, AUTH_SUBSYS_DB, "oauth2 failed: %s",
                                      error);
+       else {
+               auth_request_set_field(request, "token", req->token, "PLAIN");
+       }
        req->verify_callback(result, request);
        auth_request_unref(&request);
 }
@@ -47,6 +50,14 @@ oauth2_preinit(pool_t pool, const char *args)
 
        module = p_new(pool, struct oauth2_passdb_module, 1);
        module->db = db_oauth2_init(args);
+       module->module.default_pass_scheme = "PLAIN";
+
+       if (db_oauth2_uses_password_grant(module->db)) {
+               module->module.default_cache_key = "%u";
+       } else {
+               module->module.default_cache_key = "%u%w";
+       }
+
        return &module->module;
 }