{"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.4.0","deps":[],"features":{},"cksum":"sha256:7a9440af716db6ab8bd66c2820a5a2275b0e168be08d1484e8b70afca78ca529","sig":"ed25519:a1644a90b5f63976f252bd04ed72190bd1653198eaaceb9982891668c1053d917a16d53cae470a1a4440aa6445b085d17d229498232411c888e23bfd0069040d","key_fp":"SHA256:bkFv7568keKWVEybPdkv3PglP/WcccdGO8I/l+R9crc","yanked":false,"edition":"2026","hew":">=0.6.1, <0.7.0","registry_sig":"ed25519:b870983ef0354286012e0ba9b94b7bf3aaf9ca462b8ae26ccefc3527a49acf6f2a73ca491acef6a8137d9c7bafa6f89c4994ea31595109a04b5df430d12e8808","registry_key_fp":"SHA256:NR2yrof9/ZWkCWyhDODRU8Yvm9Lob/0yYVTdCKzMHb8","published_at":"2026-10-21T01:45:36.555Z","dl":"https://cdn.hewpkg.com/tarballs/hew/auth/oauth/0.4.0.tar.zst"}}