@multiplatform.one/keycloak 11.3.3 → 11.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/docs/PLATFORMS.md +98 -0
  2. package/package.json +11 -10
@@ -0,0 +1,98 @@
1
+ # Platform Support and Auth Strategy
2
+
3
+ ## Auth Architecture
4
+
5
+ All platforms use **Better Auth** with **Keycloak as the only IdP**. Sessions are **stateless** (JWE-encrypted cookies) — no database is required. The Better Auth server handles OAuth redirect flows; clients use the Better Auth React client for signIn/signOut/session management.
6
+
7
+ ## Supported Platforms
8
+
9
+ ### Web (One app)
10
+
11
+ - **AuthProvider:** `index.tsx` — uses Better Auth React client
12
+ - **Auth strategy:** Cookie-based session. `AuthStrategy.BetterAuth` for standard flow; falls back to `@multiplatform.one/keycloak-js` for iframe/direct-token scenarios.
13
+ - **signIn:** `client.signIn.social({ provider: "keycloak" })` — redirects to Keycloak via Better Auth server
14
+ - **signOut:** `client.signOut()` — clears server session + cookie
15
+ - **SSR:** Server reads session from cookie via `auth.api.getSession({ headers })` for authenticated server-rendering
16
+
17
+ ### Expo (React Native)
18
+
19
+ - **AuthProvider:** `index.native.tsx`, over the hand-rolled flow in `betterAuth/expoAuthFlow.native.ts`. It doesn't use the `@better-auth/expo` client, whose import graph breaks the Hermes dev bundle.
20
+ - **Auth strategy:** the flow posts `/api/auth/sign-in/social` with an `expo-origin` header, opens `/api/auth/expo-authorization-proxy` in an `expo-web-browser` auth session, and keeps the cookie the server hands back on the `?cookie=` return URL in `expo-secure-store`.
21
+ - **Server requirement:** Better Auth server must include `expo()` plugin and `{scheme}://` in `trustedOrigins`
22
+ - **Scheme:** the return URL is `Linking.createURL("/")`, so the app's own `scheme` from `app.config.js`. `keycloakConfig.expoScheme` overrides it; `createApp` leaves it unset.
23
+ - **signIn:** `keycloak.login()` opens the system browser and returns via deep link
24
+ - **signOut:** `GET /api/auth/sign-out/sso?mode=json`, then the returned Keycloak end-session URL in the same browser
25
+
26
+ ### WebExt (Browser Extension)
27
+
28
+ - **AuthProvider:** `index.webext.tsx` — uses Better Auth React client for session-based auth
29
+ - **Auth strategy:** Same cookie flow as web (`AuthStrategy.BetterAuth`) when not in iframe. Falls back to `@multiplatform.one/keycloak-js` for iframe/token scenarios.
30
+ - **Requirements:** Extension must have host permissions for the Better Auth server origin
31
+ - **signIn/signOut:** Same as web
32
+
33
+ ### Tauri
34
+
35
+ - **AuthProvider:** Uses the **web** `index.tsx` AuthProvider (Tauri renders web content in a webview)
36
+ - **Auth strategy:** Same cookie-based flow as web. The Tauri webview shares the web session.
37
+ - **Notes:** If custom-scheme redirects are needed (e.g. `tauri://`), add the scheme to `trustedOrigins` in the server config and handle the callback in Tauri's URL handler. For most use cases, the standard web flow works without modification.
38
+
39
+ ### GNOME (GTK4 / GJS)
40
+
41
+ - **AuthProvider:** none — GNOME does not mount the React auth providers. The
42
+ GTK process is the OAuth client itself, so it drives the flow directly via
43
+ `GnomeKeycloak` (`apps/one/gnome/keycloak/`).
44
+ - **Auth strategy:** Authorization Code + PKCE with a **loopback redirect**
45
+ (RFC 8252 §7.3). The app binds an ephemeral port on `127.0.0.1`, opens the
46
+ user's real browser at Keycloak, and receives the redirect on that port.
47
+ - **Token storage:** a mode-0600 JSON file in the XDG data dir
48
+ (`$XDG_DATA_HOME/one-gnome/keycloak-tokens.json`). GJS has no localStorage,
49
+ and unlike web there is no cookie session to fall back on.
50
+ - **Client requirements:** the client must be **public** (a desktop binary
51
+ cannot hold a secret) with the standard flow enabled and a redirect URI
52
+ pattern covering `http://127.0.0.1:*`. Use `KEYCLOAK_PUBLIC_CLIENT_ID`, not
53
+ `KEYCLOAK_CLIENT_ID`.
54
+ - **Transport:** the issuer must be `https`. Plaintext is rejected unless the
55
+ host is loopback _and_ the caller passes `allowInsecureLoopbackHttp` — which
56
+ the docker-realm dev entries do explicitly (`KEYCLOAK_ALLOW_INSECURE_HTTP=1`
57
+ for `make one/gnome/login`).
58
+ - **ID token:** validated on arrival — `iss`, `aud`, `azp`, `exp`, `iat`,
59
+ `nbf`, `sub` and `nonce`. The signature is **not** verified, under OIDC Core
60
+ §3.1.3.7's direct-from-the-token-endpoint-over-TLS carve-out; the https
61
+ requirement above is what makes that hold, and GJS has no crypto API to do
62
+ RS256 with.
63
+ - **Not mounted in the app:** no GNOME app entry imports `gnome/keycloak/`
64
+ yet. `GnomeKeycloak` is exercised by `make one/gnome/login` and
65
+ `gnome:auth:smoke`, both built standalone. Wiring it into the screens needs
66
+ a `useKeycloak()` GNOME binding, which does not exist.
67
+ - **Reusable core:** the protocol logic is `@multiplatform.one/keycloak/oauth`
68
+ — pure functions with injected crypto/fetch/browser/listener, so it is unit
69
+ tested without a browser or GJS, and any other non-browser target can reuse
70
+ it.
71
+
72
+ ```bash
73
+ make one/gnome/login # interactive login against the docker realm
74
+ pnpm --filter @platform/one gnome:auth:smoke # offline flow check
75
+ ```
76
+
77
+ ### VS Code (Extension Webview)
78
+
79
+ - **AuthProvider:** Uses the **web** `index.tsx` AuthProvider (VS Code webviews render web content)
80
+ - **Auth strategy:** Same cookie-based flow as web within the webview context.
81
+ - **Notes:** If the VS Code extension host (Node.js) needs auth independently of the webview, a separate server-to-server flow (e.g. device authorization or token exchange) would be needed. For webview-based UI, the standard web flow works.
82
+
83
+ ## @multiplatform.one/keycloak-js
84
+
85
+ - **This package (@multiplatform.one/keycloak):** Uses the **vendored, patched** adapter for iframe/direct-token scenarios (same API as upstream keycloak-js).
86
+
87
+ ## Environment Variables
88
+
89
+ | Variable | Description | Required |
90
+ | --------------------------- | --------------------------------------------------------------------------------------------------------------- | -------- |
91
+ | `KEYCLOAK_BASE_URL` | Keycloak URL (e.g. `http://localhost:8080`). Falls back to `BASE_URL + /auth` | No |
92
+ | `KEYCLOAK_BACKCHANNEL_URL` | Direct Keycloak URL for server-to-server calls (e.g. `http://localhost:8080`). Falls back to `${BASE_URL}/auth` | No |
93
+ | `KEYCLOAK_REALM` | Keycloak realm name | Yes |
94
+ | `KEYCLOAK_CLIENT_ID` | OAuth client ID (confidential) | Yes |
95
+ | `KEYCLOAK_CLIENT_SECRET` | OAuth client secret | Yes |
96
+ | `KEYCLOAK_PUBLIC_CLIENT_ID` | Public client ID — required by the GNOME loopback PKCE flow | GNOME |
97
+ | `SECRET` | Secret for signing/encrypting session cookies | Yes |
98
+ | `BASE_URL` | App server URL (e.g. `http://localhost:3000`) | No |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@multiplatform.one/keycloak",
3
- "version": "11.3.3",
3
+ "version": "11.4.1",
4
4
  "description": "keycloak client for multiplatform.one ecosystem",
5
5
  "keywords": [
6
6
  "auth",
@@ -20,6 +20,7 @@
20
20
  "source": "src/index.ts",
21
21
  "files": [
22
22
  "dist",
23
+ "docs",
23
24
  "src",
24
25
  "types",
25
26
  "!types/.tsbuildinfo"
@@ -55,17 +56,17 @@
55
56
  },
56
57
  "dependencies": {
57
58
  "@better-auth/expo": "~1.6.33",
58
- "@multiplatform.one/auth": "^11.3.3",
59
- "@multiplatform.one/keycloak-js": "^11.3.3",
60
- "@multiplatform.one/store": "^11.3.3",
59
+ "@multiplatform.one/auth": "^11.4.1",
60
+ "@multiplatform.one/keycloak-js": "^11.4.1",
61
+ "@multiplatform.one/store": "^11.4.1",
61
62
  "better-auth": "~1.6.33",
62
63
  "jwt-decode": "^4.0.0"
63
64
  },
64
65
  "devDependencies": {
65
- "@multiplatform.one/config": "11.3.3",
66
- "@multiplatform.one/logger": "11.3.3",
67
- "@multiplatform.one/platform": "11.3.3",
68
- "@multiplatform.one/test-utils": "11.3.3",
66
+ "@multiplatform.one/config": "11.4.1",
67
+ "@multiplatform.one/logger": "11.4.1",
68
+ "@multiplatform.one/platform": "11.4.1",
69
+ "@multiplatform.one/test-utils": "11.4.1",
69
70
  "@tamagui/build": "3.2.3",
70
71
  "@testing-library/jest-dom": "^7.0.1",
71
72
  "@testing-library/react": "^16.3.3",
@@ -79,8 +80,8 @@
79
80
  "vitest": "^4.1.12"
80
81
  },
81
82
  "peerDependencies": {
82
- "@multiplatform.one/logger": "^11.3.3",
83
- "@multiplatform.one/platform": "^11.3.3",
83
+ "@multiplatform.one/logger": "^11.4.1",
84
+ "@multiplatform.one/platform": "^11.4.1",
84
85
  "expo-linking": "~58.0.16",
85
86
  "expo-secure-store": "~58.0.2",
86
87
  "expo-web-browser": "~58.0.7",