{"metadata":{"name":"hew/auth/oauth","vers":"0.7.0","description":"Typed OAuth 2.0 client for Hew — PKCE authorization code, state validation, client credentials, and refresh","license":"MIT OR Apache-2.0","authors":["Hew Contributors"],"deps":[],"features":{},"keywords":["oauth","pkce","authentication","authorization"],"repository":"https://github.com/hew-lang/ecosystem","edition":"2026","hew":">=0.10.0, <0.12.0","readme":"# hew.auth.oauth\n\nAn actor-owned OAuth 2.0 client supporting client credentials, authorization\ncode with PKCE S256, callback-state validation, refresh, and typed endpoint\nerrors. Tokens expose optional expiry, refresh-token, and scope values as\n`Option`s.\n\nThe package is pure Hew: token requests are form-encoded POSTs sent with\n`std.net.http.client`, PKCE and state values come from\n`std.crypto.hash`, and token responses are read with `std.encoding.json`.\nIt has no native library to build.\n\n```hew\nimport hew.auth.oauth;\n\nfn main() {\n    let client = spawn oauth.Client { client_id: \"demo\", client_secret: \"secret\" };\n    match client.auth_url(\"https://authorization.example/authorize\", \"https://app.example/callback\", \"profile\", \"\") {\n        .Ok(url) => println(f\"send the user to {url}\"),\n        .Err(.Failed(error)) => println(oauth.error_message(error)),\n        .Err(_) => println(\"OAuth actor stopped before replying\"),\n    }\n    stop(client);\n    stopped(client);\n}\n```\n\n`auth_url` always adds PKCE S256 parameters, generates the `state` when you\npass an empty one, and retains both the state and the code verifier on the\nclient — so validating the callback needs no storage of your own.\n\nThe checked example at [`examples/basic.hew`](examples/basic.hew) walks that\nwhole flow and needs no authorization server, because every step up to the code\nexchange is local. Run it from the ecosystem checkout:\n\n```sh\nhew run --pkg-path . auth/oauth/examples/basic.hew\n```\n\nIt prints the authorization URL, then accepts the state `auth_url` retained and\nrejects an empty callback state as `OAuthError.InvalidInput`.\n\n## Errors\n\nToken requests are `receive fn`s declared `-> Token fails OAuthError`, so a call\nreplies `Result<Token, ActorError<OAuthError>>`: the handler's error arrives as\n`.Err(.Failed(error))`, and any other `.Err` means the actor did not reply.\n`auth_url` and `validate_state` fail the same way; `current_state` and\n`current_code_verifier` cannot fail and reply `Option<string>`.\n\n- `InvalidInput` — a local precondition failed before any request was sent:\n  an empty URL, refresh token, verifier, or callback state, or\n  `exchange_code` called before `auth_url` stored a verifier.\n- `Transport` — the token endpoint could not be reached; the message starts\n  with `transport_error:`.\n- `TokenEndpoint(status, message)` — the endpoint answered with a non-2xx\n  status, an RFC 6749 error body (`error: error_description`), a body that is\n  not JSON (`invalid_json: …`), or no `access_token`.\n- `Internal` — the system entropy source could not supply PKCE or state bytes.\n\n## Tests\n\n`tests/public_api.hew` drives every grant against a loopback token endpoint in\nthe same process; the in-file tests cover the RFC 7636 S256 vector and token\nbody parsing:\n\n```sh\nhew build --pkg-path . auth/oauth/tests/public_api.hew -o oauth-tests && ./oauth-tests\nhew test auth/oauth/oauth.hew\n```\n"},"version":{"name":"hew/auth/oauth","vers":"0.7.0","deps":[],"features":{},"cksum":"sha256:66f1667338cbc8f3a9aed25b84234246b9111668f8f92b34854a460229745d17","sig":"ed25519:bbc2153cc913c6574f2fa149d3eb87f2c719a72336143e3d2e7c1349585952abc8be32c264d2a328aa55f8d2a24aa81df7823837620d0b83224eb1f47f8ef409","key_fp":"SHA256:QDgYk38yt+UbTDqWpi+aVd+Vkirhyd7m4y+5bVuNIpg","yanked":false,"edition":"2026","hew":">=0.10.0, <0.12.0","registry_sig":"ed25519:23b73045f8905ddc16e02401721abbc6bc12d391218ed995aed419b63daaa560e4fb3dd1375331d992daf4fe50b6a4ca26b252a03ff561a4396ed2d3543d630a","registry_key_fp":"SHA256:NR2yrof9/ZWkCWyhDODRU8Yvm9Lob/0yYVTdCKzMHb8","published_at":"2026-11-13T06:01:03.323Z","dl":"https://cdn.hewpkg.com/tarballs/hew/auth/oauth/0.7.0.tar.zst"}}