Skip to content

Commit

Permalink
auth: Add caching to passdb-oauth.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergey-Kitov authored and cmouse committed Feb 19, 2019
1 parent 916d9b4 commit ce54297
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/auth/db-oauth2.c
Expand Up @@ -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;
}
2 changes: 2 additions & 0 deletions src/auth/db-oauth2.h
Expand Up @@ -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 + \
Expand Down
11 changes: 11 additions & 0 deletions src/auth/passdb-oauth2.c
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit ce54297

Please sign in to comment.