{"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.3.0","deps":[],"features":{},"cksum":"sha256:525866a8544f85aaf0b631b830dd872234d455b332f0ad343ac1c8238fd7d80d","sig":"ed25519:2caf37010d10756b06a2b4811d888908bacffc32d42f458834e6d7a0856c4ae39de83f1a156e308de943957d4448e357227f7f37b516b632c8b0018b86978a0f","key_fp":"SHA256:jLehs0udkm2NCjnfcFdvc8l8rkRR5tJ++54dk9PpbGk","yanked":false,"edition":"2026","hew":">=0.6.1, <0.7.0","registry_sig":"ed25519:d210e2226014ab8f4847cbabd42aa6e151885d1f46f062e5b878af5e29019253d9338d1710236619939bfe36417ab06de0739f6c25e89c90d08c0d66d3a72b09","registry_key_fp":"SHA256:NR2yrof9/ZWkCWyhDODRU8Yvm9Lob/0yYVTdCKzMHb8","published_at":"2026-10-17T05:38:06.959Z","dl":"https://cdn.hewpkg.com/tarballs/hew/auth/oauth/0.3.0.tar.zst"}}