{"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.2.0","deps":[],"features":{},"cksum":"sha256:1b97176b181d19faf0158f6578e6ed8630f2c80978593d4fd17ca7a01b7bc9bd","sig":"ed25519:84301d4375cce94e0d33a64a83a04ddc32977e707bc4e12837360c8c2ac9a607661b9a309717649fe1bb1ac7818f68d592679c96df711ded9195554a9ef0b500","key_fp":"SHA256:UspGxFtb7yFbHAcyG72z6OYMpTR5mLh+BO2Rht625yY","yanked":false,"edition":"2026","hew":">=0.6.0-rc1, <0.7.0","registry_sig":"ed25519:7b0e0ed335810fc2cf4f4fcf58e4f77de75403a1d5c8e432a90c8fa723332c17a12e83e6d22ea2b0303d3294f6af0c9f75b961141472179643fb6f5fba418004","registry_key_fp":"SHA256:NR2yrof9/ZWkCWyhDODRU8Yvm9Lob/0yYVTdCKzMHb8","published_at":"2026-08-15T20:03:49.534Z","dl":"https://cdn.hewpkg.com/tarballs/hew/auth/oauth/0.2.0.tar.zst"}}