User authentication and session management for web applications
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add missing READMEs; expand short ones

New READMEs for: ocaml-auth, ocaml-cose, ocaml-http, ocaml-osv,
ocaml-rego, ocaml-scitt, ocaml-sigstore, ocaml-vec3.

Expanded: ca-certs (7→40 lines), osrelease (8→45 lines).

Each includes: synopsis, installation, usage example, API overview,
and license. Skipped ocaml-cel and ocaml-chor (no code yet).

+45
+45
README.md
··· 1 + ## auth -- user authentication and session management 2 + 3 + `auth` provides OAuth-based user authentication with server-side session 4 + management for OCaml web applications. It handles the full sign-in lifecycle: 5 + redirect to provider, exchange authorization code, create or find user, issue 6 + session cookie. 7 + 8 + Sessions are stored in SQLite for revocability. Cookies are HttpOnly, 9 + SameSite=Lax, and Secure (when the base URL is HTTPS). CSRF protection on the 10 + OAuth callback uses signed state tokens. 11 + 12 + ## Installation 13 + 14 + ``` 15 + opam install auth 16 + ``` 17 + 18 + ## Quick Start 19 + 20 + ```ocaml 21 + Eio_main.run @@ fun env -> 22 + Eio.Switch.run @@ fun sw -> 23 + let fs = Eio.Stdenv.fs env in 24 + let http = Requests.v ~sw env in 25 + let store = Auth.Store.v ~sw Eio.Path.(fs / "data" / "auth.db") in 26 + let cfg = 27 + Auth.config ~oauth_provider:Oauth.Github ~client_id:"Iv1.abc" 28 + ~client_secret:"secret" ~base_url:"https://app.com" 29 + ~cookie_secret:"32-char-min-secret-for-signing!" ~http () 30 + in 31 + let routes = Auth.routes cfg store in 32 + Respond.run ~net:(Eio.Stdenv.net env) ~port:8080 33 + ~root:Eio.Path.(fs / "static") 34 + routes 35 + ``` 36 + 37 + The library registers three routes: 38 + 39 + - `GET /auth/<provider>` -- redirect to OAuth provider 40 + - `GET /auth/<provider>/callback` -- handle provider callback, create session 41 + - `POST /auth/signout` -- revoke session, clear cookie 42 + 43 + ## License 44 + 45 + ISC