Skip to main content

Crate wabot_addon_auth_pg

Crate wabot_addon_auth_pg 

Source
Expand description

§wabot-addon-auth-pg

Postgres storage for auth. Port of ApiKeyPgQueries and JwtRefreshTokenPgQueries in wabot-ts, on top of PgJsonbStore — so an API key is a document in the same table shape every other stored entity uses, and the two stacks can share it.

ⓘ
let repository = Arc::new(PgApiKeyRepository::new(pool));
register_api_key_repository(&container, repository);
register_singletons!(&container, ApiKeyGuard);

Both API keys and refresh tokens live here, because they are the same problem twice: a stored credential looked up by the hash of a secret nobody else holds.

§The lookup is by hash, and it is indexed

Only the SHA-256 hash of a secret is stored, and authentication looks a key up by that hash — database read access alone doesn’t let anyone in. That makes the hash the hot column, so it is promoted out of the JSON document and indexed; a sequential scan over every key on every request would be a denial-of-service waiting for the key table to grow.

Structs§

PgApiKeyRepository
API keys in a Postgres table.
PgRefreshTokenRepository
Refresh tokens in a Postgres table.

Functions§

register_pg_api_key_repository
Register a Postgres-backed API-key repository.
register_pg_refresh_token_repository
Register Postgres-backed refresh-token storage.