You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: office/auth0/readme.md
+24-4Lines changed: 24 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -19,7 +19,10 @@ The API represents the resource that tokens will be issued for — in this case,
19
19
-**Identifier (Audience)**: `io.bridge` (this is the logical identifier, not a URL — it must match `IO_BRIDGE_SERVER_AUTH_OAUTH2_JWT_AUDIENCE` in your `.env`)
20
20
-**Signing Algorithm**: `RS256` (default)
21
21
4. Click **Create**.
22
-
5. Note the **Identifier** value — this is your **audience**.
22
+
5. Go to the **Settings** tab of the newly created API.
23
+
6. Enable **Allow Offline Access** — this allows the desktop gateway to request a refresh token (via the `offline_access` scope) so it can automatically renew expired access tokens without requiring the user to log in again.
24
+
7. Click **Save**.
25
+
8. Note the **Identifier** value — this is your **audience**.
23
26
24
27
### Configuration mapping
25
28
@@ -29,7 +32,7 @@ The API represents the resource that tokens will be issued for — in this case,
29
32
30
33
## 3. Create a Single-Page Application (SPA)
31
34
32
-
The SPA application is used by both the **browser platform** (via `@auth0/auth0-react`) and the **desktop gateway** (via the implicit flow callback registered in `auth0/app.ts`).
35
+
The SPA application is used by both the **browser platform** (via `@auth0/auth0-react`) and the **desktop gateway** (via the Authorization Code + PKCE flow registered in `auth0/app.ts`).
33
36
34
37
1. In the Auth0 Dashboard navigate to **Applications → Applications**.
35
38
2. Click **+ Create Application**.
@@ -39,6 +42,7 @@ The SPA application is used by both the **browser platform** (via `@auth0/auth0-
39
42
4. Click **Create**.
40
43
5. Go to the **Settings** tab of the newly created application.
41
44
6. Note the **Client ID** and **Domain** — you will need them for `.env`.
45
+
7. Go to the **APIs** tab and find the **io.Bridge** API (created in step 2). Enable **User access** (Authorization Code) — this authorizes the application to request tokens for the io.Bridge API on behalf of users.
42
46
43
47
### 3.1. Configure Callback URLs and Web Origins
44
48
@@ -54,7 +58,7 @@ http://localhost:5173,
54
58
https://<your-github-pages-domain>
55
59
```
56
60
57
-
-`http://localhost:8385/login/oauth2/code/auth0` — the desktop gateway's Auth0 callback endpoint (implicit flow with `response_mode=form_post`)
61
+
-`http://localhost:8385/login/oauth2/code/auth0` — the desktop gateway's Auth0 callback endpoint (authorization code + PKCE with `response_mode=form_post`)
58
62
-`http://localhost:5173` — the Vite dev server (browser platform login)
59
63
- Add any additional deployed URLs (e.g. GitHub Pages) as needed
On startup, the **desktop gateway** (`gateway-server.config.ts`) probes the bridge by sending `POST<bridge_url>/api/nodes` with an empty JSON array:
198
202
199
203
- **2xx response** → no authentication required; the gateway proceeds with the local OS username.
200
-
- **401 + `WWW-Authenticate: Bearer`** → authentication is required; the gateway registers the Auth0 login and callback routes (`/login/auth0` and `/login/oauth2/code/auth0`), then opens the login page in the system browser. After the user authenticates, Auth0 posts the tokens back to the callback endpoint. The received access token is then used for the mesh connection to io.Bridge.
204
+
- **401 + `WWW-Authenticate: Bearer`** → authentication is required; the gateway starts the Authorization Code + PKCE flow (see below).
201
205
- **Other / unreachable** → the gateway logs a warning and proceeds without a token (the mesh will retry once the bridge becomes available).
202
206
207
+
### Authorization Code + PKCE flow
208
+
209
+
When authentication is required, the gateway:
210
+
211
+
1. Generates a **PKCE code verifier** and its SHA-256 **code challenge**.
212
+
2. Registers login (`/login/auth0`) and callback (`/login/oauth2/code/auth0`) routes on the local HTTP server.
213
+
3. Opens the Auth0 Universal Login page in the system browser with `response_type=code`, `response_mode=form_post`, and the PKCE challenge.
214
+
4. After the user authenticates, Auth0 POSTs the **authorization code** back to the callback endpoint.
215
+
5. The gateway exchanges the code (plus the PKCE verifier) for **access, ID, and refresh tokens** via `POST<issuerUrl>/oauth/token`.
216
+
6. The access token is used immediately for the mesh connection to io.Bridge.
217
+
7. A timer is scheduled to **refresh the access token** automatically (60 seconds before expiry) using the refresh token — so the gateway stays connected without requiring the user to log in again.
218
+
219
+
> **Note:** The `offline_access` scope and the API's **Allow Offline Access** setting (step 2.6) are both required for the refresh token to be issued.
220
+
221
+
> **Tip:** To test the refresh logic without waiting 24 hours, go to **Applications → APIs → io.Bridge → Settings** and lower both **Token Expiration (Seconds)** and **Token Expiration For Browser Flows (Seconds)** to the same value (e.g. `120` for 2 minutes) — the browser flow lifetime cannot exceed the maximum. The gateway refreshes 60 seconds before expiry. Remember to restore reasonable values afterwards.
222
+
203
223
The **browser platform** (`App.tsx`) uses `@auth0/auth0-react` with the `IOConnectHome` login type set to `"auth0"`, handling authentication entirely client-side.
0 commit comments