code wiki / (root) / oauth2_pkce.nx

oauth2_pkce.nx

buildroot/runtime/oauth2_pkce.nx

4876 B136 linesdepth 6pulls 8 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

syscalls.nx rand.nx sha256.nx base64.nx oauth2_pkce.nx

imports: syscalls.nxrand.nxsha256.nxbase64.nx

imported by: nobody (leaf or entry point)

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

main pkce_verifier_new rand_bytes rand_open_urandom sys_read pkce_map_char pkce_challenge b64_encode b64_enc_char

structs

none

consts

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

functions

42func pkce_map_char(v: i64) -> i64 {
called by 1: pkce_verifier_new
53func pkce_verifier_new(out: *u8) -> i64 {
called by 1: main calls 2: rand_bytespkce_map_char
67func pkce_challenge(verifier: *u8, verifier_len: i64,
called by 1: main calls 1: b64_encode
96func main() -> i64 {