@bigio/better-auth-electron 1.0.2 → 1.0.3
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.
- package/README.md +61 -24
- package/dist/main.js +2177 -1
- package/dist/main.js.map +1 -1
- package/dist/metafile-esm.json +1 -1
- package/dist/options.d.ts +1 -0
- package/dist/options.js.map +1 -1
- package/dist/renderer.js.map +1 -1
- package/dist/server.js.map +1 -1
- package/dist/web.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,40 +1,34 @@
|
|
|
1
1
|
## I'm currently studying the official implementation; the documentation is still rough but will be improved soon. I'm eager and looking forward to exchanging ideas with everyone.
|
|
2
2
|
|
|
3
3
|
Based on my study of the official implementation code, I have decided on the following to-do list:
|
|
4
|
-
**1. Architecture: The "Silent Handoff" (Stateless & Secure)**
|
|
5
4
|
|
|
6
|
-
|
|
7
|
-
* *Action*: Strip the `Set-Cookie` header (specifically the session token) from the response to prevent overwriting the user's browser session.
|
|
8
|
-
* *Goal*: Achieve strict physical isolation between Web Session and Electron Session.
|
|
5
|
+
**1. Architecture: The "Silent Handoff" (Stateless & Secure)**
|
|
9
6
|
|
|
7
|
+
- [ ] **Server-Side Cookie Interception**: Modify `electron-server-plugin` to intercept the OAuth callback response.
|
|
8
|
+
- _Action_: Strip the `Set-Cookie` header (specifically the session token) from the response to prevent overwriting the user's browser session.
|
|
9
|
+
- _Goal_: Achieve strict physical isolation between Web Session and Electron Session.
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
- [ ] **Stateless OAuth Flow**: Ensure the OAuth flow relies solely on the encrypted `Ticket` mechanism, making the browser a purely stateless transport layer for Electron authentication.
|
|
12
12
|
|
|
13
13
|
**2. Security & Hardening**
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
* [ ] **User-Agent Scrubbing**: Global removal of "Electron" tokens from the `User-Agent` string at the `app.on('ready')` stage.
|
|
20
|
-
* *Reason*: Bypass WAF/Anti-Bot protections that block Electron-based requests during the ticket exchange phase.
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
* [ ] **Automated CSP Injection**: Implement `onHeadersReceived` interceptor in the Main Process.
|
|
24
|
-
* *Action*: Automatically append the backend API URL to the `connect-src` directive.
|
|
25
|
-
* *Goal*: Provide a "Zero-Config" experience by preventing CSP violations without requiring users to manually edit `index.html`.
|
|
15
|
+
- [ ] **Secure Persistence**: Implement `safeStorage` (DPAPI/Keychain) for encrypting the persisted PKCE Verifier on disk.
|
|
16
|
+
- _Reason_: Prevent plaintext credentials from resting on the file system.
|
|
26
17
|
|
|
18
|
+
- [ ] **User-Agent Scrubbing**: Global removal of "Electron" tokens from the `User-Agent` string at the `app.on('ready')` stage.
|
|
19
|
+
- _Reason_: Bypass WAF/Anti-Bot protections that block Electron-based requests during the ticket exchange phase.
|
|
27
20
|
|
|
21
|
+
- [done] ~~**Automated CSP Injection**: Implement `onHeadersReceived` interceptor in the Main Process.~~
|
|
22
|
+
- ~~_Action_: Automatically append the backend API URL to the `connect-src` directive.~~
|
|
23
|
+
- ~~_Goal_: Provide a "Zero-Config" experience by preventing CSP violations without requiring users to manually edit `index.html`.~~
|
|
28
24
|
|
|
29
25
|
**3. Developer Experience (DX) & API**
|
|
30
26
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
* [ ] **Smart Web Handoff UI (Optional/Next)**: Update the web-side confirmation page to detect and display the currently logged-in web user, offering a "Continue as [User]" button for a seamless transition.
|
|
27
|
+
- [ ] **Enhanced Renderer API**: Refactor `getActions` to introduce a dedicated `authClient.bigio` namespace.
|
|
28
|
+
- _Feature_: Implement `authClient.bigio.signIn({ provider: 'github' })` wrapper.
|
|
29
|
+
- _Implementation_: Utilize `window.open` (intercepted by Main) or IPC to trigger the flow, keeping the API consistent with the official web client style.
|
|
37
30
|
|
|
31
|
+
- [ ] **Smart Web Handoff UI (Optional/Next)**: Update the web-side confirmation page to detect and display the currently logged-in web user, offering a "Continue as [User]" button for a seamless transition.
|
|
38
32
|
|
|
39
33
|
# @bigio/better-auth-electron
|
|
40
34
|
|
|
@@ -102,6 +96,28 @@ export const auth = betterAuth({
|
|
|
102
96
|
|
|
103
97
|
Use `mainInjection` to setup IPC handlers and deep linking strategies. This automatically handles the "protocol" opening events.
|
|
104
98
|
|
|
99
|
+
### Security & CSP Configuration
|
|
100
|
+
|
|
101
|
+
** IMPORTANT: Clean up your `index.html`**
|
|
102
|
+
|
|
103
|
+
This plugin automatically injects a rigorous, production-ready **Content Security Policy (CSP)** via the Main Process.
|
|
104
|
+
|
|
105
|
+
**You CAN remove** any manual CSP `<meta>` tags from your `index.html` (renderer). Leaving them in will cause the browser to enforce the "intersection" of both policies, likely breaking your Auth flow (e.g., blocking the OAuth popup or API connection).
|
|
106
|
+
|
|
107
|
+
**DELETE this from your `index.html`:**
|
|
108
|
+
|
|
109
|
+
```html
|
|
110
|
+
<meta
|
|
111
|
+
http-equiv="Content-Security-Policy"
|
|
112
|
+
content="
|
|
113
|
+
default-src 'self';
|
|
114
|
+
script-src 'self';
|
|
115
|
+
style-src 'self' 'unsafe-inline';
|
|
116
|
+
img-src 'self' data:;
|
|
117
|
+
connect-src 'self' http://localhost;
|
|
118
|
+
" />
|
|
119
|
+
```
|
|
120
|
+
|
|
105
121
|
```typescript
|
|
106
122
|
import { app, BrowserWindow } from 'electron'
|
|
107
123
|
import { mainInjection } from '@bigio/better-auth-electron/main'
|
|
@@ -114,8 +130,14 @@ const { windowInjection, whenReadyInjection } = mainInjection({
|
|
|
114
130
|
PROVIDERS: ['github', 'google'],
|
|
115
131
|
BETTER_AUTH_BASEURL: 'http://localhost:3002',
|
|
116
132
|
FRONTEND_URL: 'http://localhost:3001/oauth',
|
|
117
|
-
|
|
118
|
-
|
|
133
|
+
CONTENT_SECURITY_POLICY: '',
|
|
134
|
+
/**
|
|
135
|
+
* [Optional] Content Security Policy (CSP) Configuration
|
|
136
|
+
* * Strategy: "All-or-Nothing"
|
|
137
|
+
* - undefined (Default): The plugin automatically injects a secure, production-ready CSP (The "MVP" Fallback).
|
|
138
|
+
* - string: The plugin uses YOUR string exactly. No merging, no magic. You take full control.
|
|
139
|
+
*/
|
|
140
|
+
CONTENT_SECURITY_POLICY: "default-src 'self'; ...", // override completely
|
|
119
141
|
})
|
|
120
142
|
|
|
121
143
|
function createWindow(): void {
|
|
@@ -134,6 +156,21 @@ app.whenReady().then(() => {
|
|
|
134
156
|
})
|
|
135
157
|
```
|
|
136
158
|
|
|
159
|
+
**If CONTENT_SECURITY_POLICY is not provided, the plugin applies the following strictly secure rules to the Main Frame (index.html) automatically. This ensures Auth works out-of-the-box while keeping your app secure.**
|
|
160
|
+
|
|
161
|
+
```http
|
|
162
|
+
default-src 'self';
|
|
163
|
+
script-src 'self';
|
|
164
|
+
style-src 'self' 'unsafe-inline';
|
|
165
|
+
# Allows loading images from 'self', OAuth providers (https:), and your Auth Server
|
|
166
|
+
img-src 'self' data: blob: https: ${BETTER_AUTH_BASEURL};
|
|
167
|
+
# Strictly restricts API connections to 'self' and your Auth Server
|
|
168
|
+
connect-src 'self' ${BETTER_AUTH_BASEURL};
|
|
169
|
+
font-src 'self' data:;
|
|
170
|
+
# Prevents clickjacking attacks
|
|
171
|
+
frame-ancestors 'none';
|
|
172
|
+
```
|
|
173
|
+
|
|
137
174
|
### 3. Web Client Initialization (`src/web/client.ts`)
|
|
138
175
|
|
|
139
176
|
Configure the client-side plugin. Note the usage of `setLazyClient` to handle circular dependencies or lazy initialization patterns effectively.
|