Skip to content

Commit b9f8c34

Browse files
authored
Merge pull request #10 from gcclinux/box-cloud
feat: Implemented Cloud provider Box
2 parents f4aee95 + f733980 commit b9f8c34

25 files changed

Lines changed: 6972 additions & 11 deletions

docs/BOX_SETUP.md

Lines changed: 301 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,301 @@
1+
# Box Integration Setup Guide
2+
3+
This guide walks you through setting up Box OAuth integration for EasyEditor's EasyNotes feature.
4+
5+
## Overview
6+
7+
To enable users to connect their Box accounts to EasyEditor, you need to:
8+
1. Create a Box App in the Box Developer Console
9+
2. Configure OAuth 2.0 settings and scopes
10+
3. Get your Client ID and Client Secret
11+
4. Add these credentials to your environment variables
12+
13+
## Step 1: Create a Box App
14+
15+
1. **Go to Box Developer Console**
16+
- Visit: https://app.box.com/developers/console
17+
- Sign in with your Box account (or create one if needed)
18+
19+
2. **Click "Create New App"**
20+
21+
3. **Select App Type**
22+
- Select: **Custom App**
23+
- This is the standard option for OAuth 2.0 integrations
24+
25+
4. **Choose Authentication Method**
26+
- Select: **User Authentication (OAuth 2.0)**
27+
- This enables the standard OAuth 2.0 flow with PKCE support
28+
29+
5. **Name Your App**
30+
- Enter a unique name, e.g., "EasyEditor" or "EasyEditor Notes"
31+
- Add a description (optional but recommended)
32+
33+
6. **Click "Create App"**
34+
35+
## Step 2: Configure OAuth Settings
36+
37+
After creating the app, navigate to the app's "Configuration" tab:
38+
39+
### 2.1 OAuth 2.0 Redirect URIs
40+
41+
1. **Redirect URIs**
42+
- Scroll to the "OAuth 2.0 Redirect URI" section
43+
- Add your redirect URIs (where Box sends users after authentication)
44+
- For development:
45+
```
46+
http://localhost:3024/box-oauth-callback.html
47+
```
48+
- For production:
49+
```
50+
https://easyeditor.co.uk/box-oauth-callback.html
51+
```
52+
- For Tauri desktop app:
53+
```
54+
http://localhost:3024/box-oauth-callback.html
55+
```
56+
57+
2. **CORS Domains**
58+
- Add allowed origins for CORS requests:
59+
```
60+
http://localhost:3024
61+
https://easyeditor.co.uk
62+
```
63+
64+
### 2.2 Application Scopes
65+
66+
In the "Application Scopes" section, enable:
67+
68+
1. **Read all files and folders stored in Box**
69+
- Required for: Listing notes, downloading files
70+
71+
2. **Write all files and folders stored in Box**
72+
- Required for: Creating notes, uploading, saving changes, deleting
73+
74+
These correspond to the `root_readwrite` scope which grants full read/write access to the user's Box content.
75+
76+
**Important**: After changing scopes, save your configuration. Users may need to re-authenticate to get updated permissions.
77+
78+
### 2.3 Application Folder
79+
80+
- EasyEditor will create an "Easyeditor" folder in the root of the user's Box account
81+
- All notes will be stored in this folder
82+
- The folder is created automatically on first connection
83+
84+
## Step 3: Get Your Credentials
85+
86+
On the app's "Configuration" tab:
87+
88+
1. **Client ID**
89+
- Located in the "OAuth 2.0 Credentials" section
90+
- Copy this value
91+
- Example: `abc123def456ghi789jkl012mno345pq`
92+
93+
2. **Client Secret**
94+
- Located in the "OAuth 2.0 Credentials" section
95+
- Click "Fetch Client Secret" to reveal it
96+
- Copy this value
97+
- **Keep this secret!** Never commit it to version control
98+
99+
## Step 4: Add Credentials to Environment Variables
100+
101+
### For Development
102+
103+
Create or update your `.env.local` file in the project root:
104+
105+
```bash
106+
# Box OAuth Credentials (Development)
107+
VITE_BOX_CLIENT_ID=your_client_id_here
108+
VITE_BOX_CLIENT_SECRET=your_client_secret_here
109+
```
110+
111+
### For Production
112+
113+
Set environment variables in your production environment:
114+
115+
```bash
116+
# Box OAuth Credentials (Production)
117+
VITE_BOX_CLIENT_ID_PROD=your_production_client_id
118+
VITE_BOX_CLIENT_SECRET_PROD=your_production_client_secret
119+
```
120+
121+
**Security Notes**:
122+
- Never commit `.env.local` to git (it's already in `.gitignore`)
123+
- Use different apps for development and production if possible
124+
- Rotate secrets periodically
125+
- Store production secrets in your deployment platform's secret manager
126+
127+
## Step 5: Test the Integration
128+
129+
### Development Testing
130+
131+
1. **Start your development server**
132+
```bash
133+
npm run dev
134+
```
135+
136+
2. **Open EasyEditor** in your browser (http://localhost:3024)
137+
138+
3. **Test the OAuth flow**:
139+
- Open EasyNotes sidebar
140+
- Click "Connect" next to Box
141+
- You should see a Box login popup
142+
- After approving, the popup should close and return to EasyEditor
143+
- Box should show as "Connected"
144+
145+
4. **Test file operations**:
146+
- Create a new note in Box
147+
- Open the note
148+
- Edit and save
149+
- Check your Box account to verify the file was created in the "Easyeditor" folder
150+
151+
### Production Testing
152+
153+
Before deploying to production:
154+
155+
1. **Update redirect URIs** in Box Developer Console to include production URLs
156+
2. **Set production environment variables** in your hosting platform
157+
3. **Test OAuth flow** on production domain
158+
4. **Verify file operations** work correctly
159+
160+
## Troubleshooting
161+
162+
### "Invalid redirect_uri" Error
163+
164+
**Problem**: Box rejects the redirect URI during OAuth flow
165+
166+
**Solution**:
167+
- Verify the redirect URI in your app settings exactly matches the one being used
168+
- Box requires an exact match including path (e.g., `/box-oauth-callback.html`)
169+
- Ensure the URI is using the correct protocol (http vs https)
170+
- Check for trailing slashes
171+
172+
### "Invalid client_id" Error
173+
174+
**Problem**: Box doesn't recognize your Client ID
175+
176+
**Solution**:
177+
- Double-check you copied the Client ID correctly
178+
- Ensure there are no extra spaces or characters
179+
- Verify the environment variable is being loaded (check browser console)
180+
- Confirm the app is not in a disabled state in the Developer Console
181+
182+
### "Insufficient permissions" Error
183+
184+
**Problem**: App doesn't have required scopes
185+
186+
**Solution**:
187+
- Go to Configuration tab in Box Developer Console
188+
- Enable "Read all files and folders" and "Write all files and folders" scopes
189+
- Save the configuration
190+
- Users may need to re-authenticate to get new permissions
191+
192+
### Files Not Appearing in Box
193+
194+
**Problem**: Notes are created but don't show up in Box
195+
196+
**Solution**:
197+
- Files are stored in the "Easyeditor" folder in the root of your Box account
198+
- Check the Box web interface at https://app.box.com
199+
- Verify the folder was created successfully
200+
- Check browser console for API errors
201+
202+
### Token Expired Errors
203+
204+
**Problem**: "Token expired" or "Invalid token" errors
205+
206+
**Solution**:
207+
- The implementation includes automatic token refresh
208+
- If refresh fails, users need to reconnect
209+
- Check that refresh tokens are being stored correctly
210+
- Box access tokens expire after 60 minutes
211+
- Box refresh tokens expire after 60 days of inactivity
212+
213+
### "Rate limited" Error
214+
215+
**Problem**: Too many API requests in a short period
216+
217+
**Solution**:
218+
- Box enforces rate limits on API calls
219+
- Wait a moment and retry the operation
220+
- The implementation includes automatic retry handling
221+
- If persistent, reduce the frequency of operations
222+
223+
## Box API Specifics
224+
225+
### Token Lifetimes
226+
227+
- **Access Token**: Expires after 60 minutes
228+
- **Refresh Token**: Expires after 60 days of inactivity (single use — each refresh returns a new refresh token)
229+
230+
### Upload Endpoint
231+
232+
Box uses a separate upload endpoint from its main API:
233+
- **Main API**: `https://api.box.com/2.0/`
234+
- **Upload API**: `https://upload.box.com/api/2.0/`
235+
236+
This is handled automatically by the EasyEditor implementation.
237+
238+
### Folder Structure
239+
240+
```
241+
Box Root (folder ID: "0")
242+
└── Easyeditor/
243+
├── note1.md
244+
├── note2.md
245+
└── ...
246+
```
247+
248+
## Security Best Practices
249+
250+
1. **Never expose secrets**
251+
- Keep Client Secret in environment variables only
252+
- Don't commit to version control
253+
- Don't log secrets in console
254+
255+
2. **Use PKCE** (Proof Key for Code Exchange)
256+
- Already implemented in the EasyEditor Box provider
257+
- Adds extra security layer for OAuth in public clients
258+
259+
3. **Validate redirect URIs**
260+
- Only add trusted domains
261+
- Use HTTPS in production
262+
263+
4. **Rotate credentials**
264+
- Periodically generate a new Client Secret in the Developer Console
265+
- Update environment variables
266+
- Users will need to reconnect
267+
268+
5. **Monitor usage**
269+
- Check Box Developer Console for usage stats
270+
- Watch for unusual patterns
271+
- Set up alerts for errors
272+
273+
## Additional Resources
274+
275+
- **Box Developer Documentation**: https://developer.box.com/
276+
- **Box OAuth 2.0 Guide**: https://developer.box.com/guides/authentication/oauth2/
277+
- **Box API Reference**: https://developer.box.com/reference/
278+
- **Box Developer Console**: https://app.box.com/developers/console
279+
- **Box Community Forum**: https://forum.box.com/
280+
281+
## Next Steps
282+
283+
After completing this setup:
284+
285+
1. ✅ Box App created
286+
2. ✅ OAuth 2.0 settings configured
287+
3. ✅ Credentials added to environment variables
288+
4. ✅ Development testing completed
289+
5. 🔄 Ready to use Box integration (follow tasks.md)
290+
6. 🔄 Production deployment and testing
291+
292+
---
293+
294+
**Need Help?**
295+
296+
If you encounter issues:
297+
1. Check the Troubleshooting section above
298+
2. Review Box API documentation
299+
3. Check browser console for error messages
300+
4. Verify environment variables are loaded correctly
301+
5. Test with Box API Reference explorer to isolate issues

firebase.json

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,24 @@
11
{
22
"hosting": {
3-
"source": ".",
3+
"public": "dist",
44
"ignore": [
55
"firebase.json",
66
"**/.*",
77
"**/node_modules/**"
88
],
9-
"frameworksBackend": {
10-
"region": "europe-west1"
11-
}
9+
"rewrites": [
10+
{
11+
"source": "/api/box-oauth/oauth2/token",
12+
"function": "boxOAuthProxy"
13+
},
14+
{
15+
"source": "/api/box-oauth/oauth2/revoke",
16+
"function": "boxRevokeProxy"
17+
}
18+
]
19+
},
20+
"functions": {
21+
"source": "functions",
22+
"codebase": "easyeditor"
1223
}
1324
}

0 commit comments

Comments
 (0)