{"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.6.0","deps":[],"features":{},"cksum":"sha256:00e77e6f29685df8aab2f55671a92ce1e72fa237bcaff1072aa6cf2da464b705","sig":"ed25519:31341ec6998c113148de928d0b47741005a97e5efe9e325acd2e980aaeeaf1660fb7310ef9ab48c5c0690cfbef43b1bf8c6c409376d7668bbd9d6c067d0a5309","key_fp":"SHA256:CB3Ski8183EXzxoy+uSuMpWTxvd/4AlB8CThZu0ZG74","yanked":false,"edition":"2026","hew":">=0.9.0, <0.10.0","registry_sig":"ed25519:6ca2e0f0dc4a1e1b7c2db2812dd6a8a8bbbe2a2d15a03b211b4460e125d856b6e8888079ec7ea526d738c9560784bd6941c984bd4774cacf5b70b7c76e82e107","registry_key_fp":"SHA256:NR2yrof9/ZWkCWyhDODRU8Yvm9Lob/0yYVTdCKzMHb8","published_at":"2026-10-24T11:53:51.351Z","dl":"https://cdn.hewpkg.com/tarballs/hew/auth/oauth/0.6.0.tar.zst"}}