1/*-------------------------------------------------------------------------
4 * Test module for serverside OAuth token validation callbacks
6 * Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
7 * Portions Copyright (c) 1994, Regents of the University of California
9 * src/test/modules/oauth_validator/validator.c
11 *-------------------------------------------------------------------------
31/* Callback implementations (exercise all three) */
45 * Extension entry point. Sets up GUCs for use by tests:
47 * - oauth_validator.authn_id Sets the user identifier to return during token
48 * validation. Defaults to the username in the
51 * - oauth_validator.authorize_tokens
52 * Sets whether to successfully validate incoming
53 * tokens. Defaults to true.
59 "Authenticated identity to use for future connections",
67 "Should tokens be marked valid?",
79 * Validator module entry point.
87 #define PRIVATE_COOKIE ((void *) 13579)
90 * Startup callback, to set up private data for the validator.
96 * Make sure the server is correctly setting sversion. (Real modules
97 * should not do this; it would defeat upgrade compatibility.)
99 if (
state->sversion != PG_VERSION_NUM)
100 elog(
ERROR,
"oauth_validator: sversion set to %d",
state->sversion);
106 * Shutdown callback, to tear down the validator.
111 /* Check to make sure our private state still exists. */
113 elog(
PANIC,
"oauth_validator: private state cookie changed to %p in shutdown",
114 state->private_data);
118 * Validator implementation. Logs the incoming data and authorizes the token by
119 * default; the behavior can be modified via the module's GUC settings.
123 const char *
token,
const char *role,
126 /* Check to make sure our private state still exists. */
128 elog(
ERROR,
"oauth_validator: private state cookie changed to %p in validate",
129 state->private_data);
131 elog(
LOG,
"oauth_validator: token=\"%s\", role=\"%s\"",
token, role);
132 elog(
LOG,
"oauth_validator: issuer=\"%s\", scope=\"%s\"",
void DefineCustomStringVariable(const char *name, const char *short_desc, const char *long_desc, char **valueAddr, const char *bootValue, GucContext context, int flags, GucStringCheckHook check_hook, GucStringAssignHook assign_hook, GucShowHook show_hook)
void DefineCustomBoolVariable(const char *name, const char *short_desc, const char *long_desc, bool *valueAddr, bool bootValue, GucContext context, int flags, GucBoolCheckHook check_hook, GucBoolAssignHook assign_hook, GucShowHook show_hook)
void MarkGUCPrefixReserved(const char *className)
char * pstrdup(const char *in)
#define PG_OAUTH_VALIDATOR_MAGIC
const OAuthValidatorCallbacks * _PG_oauth_validator_module_init(void)
static bool authorize_tokens
static void validator_startup(ValidatorModuleState *state)
static void validator_shutdown(ValidatorModuleState *state)
static const OAuthValidatorCallbacks validator_callbacks
static bool validate_token(const ValidatorModuleState *state, const char *token, const char *role, ValidatorModuleResult *res)