PostgreSQL authentication handshakes: trust (AuthenticationOk), cleartext password, MD5, and SASL/SCRAM-SHA-256. Internal to the pg package. Each handshake consumes backend messages through the final AuthenticationOk, leaving the socket positioned for ParameterStatus.

On success these return true; on failure they return a Result.Err carrying the PostgreSQL error details, which ::pg/connect propagates to its caller.

Values

AUTH-CLEARTEXT

AUTH-CLEARTEXT: Int 3

AUTH-MD5

AUTH-MD5: Int 5

AUTH-OK

AUTH-OK: Int 0

AUTH-SASL

AUTH-SASL: Int 10

AUTH-SASL-CONTINUE

AUTH-SASL-CONTINUE: Int 11

AUTH-SASL-FINAL

AUTH-SASL-FINAL: Int 12

GS2-HEADER-B64

GS2-HEADER-B64: Str "biws"

MECHANISM

MECHANISM: Str "SCRAM-SHA-256"

Functions

run-auth

fn (socket, user: Str, password: Str, msg: Map): Any

Handle the authentication exchange given the first Authentication ('R') message. Returns true once authenticated, or an Err with the failure details.

Example

socket ::hot::tcp/connect("127.0.0.1", 5432)
::hot::tcp/write(socket, ::pg::wire/startup-message("app", "app"))
msg ::pg::wire/read-message(socket)
if(eq(msg.type, "R"), ::pg::auth/run-auth(socket, "app", ::hot::ctx/get("pg.password"), msg), false)