code wiki / (root) / nx_oauth2_pkce.nx

nx_oauth2_pkce.nx

buildroot/runtime/nx_oauth2_pkce.nx

5003 B142 linesdepth 5pulls 7 transitivereach 0 importersview sourcekind tool
docsdependenciesstructsconstsfunctions

about

oauth2_pkce.nx -- Proof Key for Code Exchange (RFC 7636). Mandatory OAuth 2.0 extension for public clients (mobile apps, SPAs, CLI tools) that can't keep a client_secret secret. Also recommended for confidential clients per OAuth 2.1 draft. Flow: 1. Client generates a random 43-128 char verifier. 2. Client sends challenge = BASE64URL(SHA-256(verifier)) to authorize endpoint along with code_challenge_method=S256. 3. Server stores challenge + issues auth code. 4. Client redeems code + sends original verifier to token endpoint. 5. Server re-derives challenge from verifier, compares; if equal, issues access token. This module ships: - pkce_verifier_new(out) -> random 43-char - pkce_challenge(verifier, verifier_len, out) -> challenge Composes rand.nx + sha256.nx + base64.nx (with URL-safe + unpadded normalisation inline). Invariants: PKCE1 Verifier chars drawn from [A-Z a-z 0-9 - . _ ~] per RFC 7636 ยง4.1 unreserved set. 43 chars default ~= 256 bits of entropy. PKCE2 Challenge = BASE64URL(SHA256(verifier)) without padding ('=' stripped). PKCE3 Output is ASCII only; safe to embed in URLs without further encoding.

dependencies 4 imports · 0 importers

nx_syscalls.nx nx_rand.nx nx_sha256.nx nx_base64.nx nx_oauth2_pkce.nx

imports: nx_syscalls.nxnx_rand.nxnx_sha256.nxnx_base64.nx

imported by: nobody (leaf or entry point)

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main sys_mmap pkce_verifier_new rand_bytes rand_open_urandom sys_openat_rd sys_read sys_close pkce_map_char pkce_challenge sys_mmap ↻ sha256_digest sys_mmap ↻ sha256_init sys_mmap ↻ sha256_k sha256_update sha256_compress_ni_blocks blk_set_byte sha256_compress sha256_compress_ni blk_word blk_byte sha256_final blk_set_byte ↻ sha256_compress ↻ b64_encode b64_enc_char

structs

none

consts

44const PKCE_VERIFIER_DEFAULT_LEN: i64 = 43
45const PKCE_CHALLENGE_LEN: i64 = 43 // base64url(sha256(x)) w/o pad

functions

48func pkce_map_char(v: i64) -> i64
called by 1: pkce_verifier_new
59func pkce_verifier_new(out: *u8) -> i64
called by 1: main calls 2: rand_bytespkce_map_char
73func pkce_challenge(verifier: *u8, verifier_len: i64,
102func main() -> i64