> For the complete documentation index, see [llms.txt](https://docs.postgresql.tw/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.postgresql.tw/19/server-programming/oauth-validators/oauth-validator-init.md). Agents can also search and read this documentation through its [MCP server](https://docs.postgresql.tw/~gitbook/mcp).

# 50.2. 初始化函式 \#

### 50.2. 初始化函式 [#](#oauth-validator-init) <a href="#oauth-validator-init" id="oauth-validator-init"></a>

OAuth 驗證器模組是從 [oauth\_validator\_libraries](https://docs.postgresql.tw/19/server-administration/runtime-config/runtime-config-connection.md#GUC-OAUTH-VALIDATOR-LIBRARIES) 所列出的共享程式庫中動態載入的。模組會在有進行中的登入程序提出要求時，依需要載入。系統會使用一般的程式庫搜尋路徑來定位該程式庫。為了提供驗證器回呼函式，並表明該程式庫是一個 OAuth 驗證器模組，程式庫必須提供一個名為 `_PG_oauth_validator_module_init` 的函式。這個函式的回傳值必須是一個指向 `OAuthValidatorCallbacks` 結構型別的指標，其中包含一個魔術數字，以及指向該模組各個權杖驗證函式的指標。回傳的指標必須具有伺服器生命週期，通常的做法是把它定義為全域範圍中的 `static const` 變數。

```

typedef struct OAuthValidatorCallbacks
{
    uint32        magic;            /* must be set to PG_OAUTH_VALIDATOR_MAGIC */

    ValidatorStartupCB startup_cb;
    ValidatorShutdownCB shutdown_cb;
    ValidatorValidateCB validate_cb;
} OAuthValidatorCallbacks;

typedef const OAuthValidatorCallbacks *(*OAuthValidatorModuleInit) (void);
```

只有 `validate_cb` 回呼函式是必要的，其餘皆為選用。

***

原文：[PostgreSQL 18.6 Documentation](https://www.postgresql.org/docs/18/oauth-validator-init.html)（原文版本：18.6；核對日期：2026-09-24）


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.postgresql.tw/19/server-programming/oauth-validators/oauth-validator-init.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
