Skip to content

Commit ea077d6

Browse files
committed
feat(feishu): OAuth improvements and permission management (#71)
- Dynamic redirect_uri support for multi-environment deployment - Complete refresh_token expiry handling - Fix OAuth scope issues with Feishu API - Enhanced documentation with permission requirements
1 parent 000abd3 commit ea077d6

File tree

4 files changed

+283
-50
lines changed

4 files changed

+283
-50
lines changed

docs/content.en/docs/references/connectors/feishu.md

Lines changed: 126 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,16 @@ The Feishu connector indexes cloud documents from Feishu, including documents, s
1414
- 🔐 **Dual Authentication**: OAuth 2.0 and user access token authentication (choose one)
1515
-**Efficient Sync**: Scheduled and manual synchronization
1616
- 🔄 **Recursive Search**: Automatically search folder contents recursively
17+
- 🔄 **Token Auto-refresh**: OAuth authentication supports automatic refresh of access_token and refresh_token
18+
- 🌐 **Dynamic Redirect**: Supports dynamic OAuth redirect URI construction for multi-environment deployment
1719

1820
## Authentication Methods
1921

2022
The Feishu connector supports two authentication methods. **You must choose one**:
2123

2224
### 1. OAuth 2.0 Authentication (Recommended)
2325

24-
Uses OAuth flow to automatically obtain user access tokens with automatic refresh support.
26+
Uses OAuth flow to automatically obtain user access tokens with automatic refresh support and expiration time management.
2527

2628
#### Requirements
2729
- `client_id`: Feishu app Client ID
@@ -32,13 +34,15 @@ Uses OAuth flow to automatically obtain user access tokens with automatic refres
3234
1. User creates Feishu datasource with `client_id` and `client_secret`
3335
2. Clicks "Connect" button, system redirects to Feishu authorization page
3436
3. User completes authorization, system automatically obtains `access_token` and `refresh_token`
35-
4. System automatically updates datasource configuration with complete OAuth information
37+
4. System automatically updates datasource configuration with complete OAuth information and expiration times
3638

3739
#### Advantages
3840
- High security, no manual token management required
39-
- Automatic token refresh support
41+
- Automatic access_token and refresh_token refresh support
42+
- Automatic token expiration time management
4043
- Automatic user information retrieval
4144
- Compliant with OAuth 2.0 standards
45+
- Supports multi-environment deployment (dynamic redirect URI)
4246

4347
### 2. User Access Token Authentication (Alternative)
4448

@@ -58,6 +62,82 @@ Directly uses user access tokens, suitable for scenarios with existing tokens.
5862
- Manual token updates needed after expiration
5963
- Relatively lower security
6064

65+
## Feishu App Permission Configuration
66+
67+
### Required Permissions
68+
69+
The Feishu connector requires the following permissions to function properly:
70+
71+
| Permission | Permission Code | Description | Purpose |
72+
|------------|-----------------|-------------|---------|
73+
| **Cloud Document Access** | `drive:drive` | Access user's cloud documents, spreadsheets, slides, etc. | Read and index cloud document content |
74+
| **Knowledge Base Retrieval** | `space:document:retrieve` | Retrieve documents from knowledge bases | Access knowledge bases and space documents |
75+
| **Offline Access** | `offline_access` | Access resources when user is offline | Support background sync tasks |
76+
77+
### Permission Application Steps
78+
79+
1. **Login to Feishu Open Platform**
80+
- Visit [https://open.feishu.cn/](https://open.feishu.cn/)
81+
- Login with Feishu account
82+
83+
2. **Create Application**
84+
- Click "Create Application"
85+
- Select "Enterprise Self-built Application"
86+
- Fill in application name and description
87+
88+
3. **Apply for Permissions**
89+
- Go to "Permission Management" page
90+
- Search and add the three permissions above
91+
- Submit permission application
92+
93+
4. **Publish Application**
94+
- After completing permission application, publish application to enterprise
95+
- Record the app's `Client ID` and `Client Secret`
96+
97+
### Permission Description
98+
99+
- **`drive:drive`**: This is the core permission for accessing cloud documents, allowing the app to read user's documents, spreadsheets, slides, and other files
100+
- **`space:document:retrieve`**: Used to access documents in knowledge bases and spaces, expanding document access scope
101+
- **`offline_access`**: Allows the app to access resources when user is offline, which is crucial for background sync tasks
102+
103+
## Feishu App Permission Configuration
104+
105+
### Required Permissions
106+
107+
The Feishu connector requires the following permissions to function properly:
108+
109+
| Permission | Permission Code | Description | Purpose |
110+
|------------|-----------------|-------------|---------|
111+
| **Cloud Document Access** | `drive:drive` | Access user's cloud documents, spreadsheets, slides, etc. | Read and index cloud document content |
112+
| **Knowledge Base Retrieval** | `space:document:retrieve` | Retrieve documents from knowledge bases | Access knowledge bases and space documents |
113+
| **Offline Access** | `offline_access` | Access resources when user is offline | Support background sync tasks |
114+
115+
### Permission Application Steps
116+
117+
1. **Login to Feishu Open Platform**
118+
- Visit [https://open.feishu.cn/](https://open.feishu.cn/)
119+
- Login with Feishu account
120+
121+
2. **Create Application**
122+
- Click "Create Application"
123+
- Select "Enterprise Self-built Application"
124+
- Fill in application name and description
125+
126+
3. **Apply for Permissions**
127+
- Go to "Permission Management" page
128+
- Search and add the three permissions above
129+
- Submit permission application
130+
131+
4. **Publish Application**
132+
- After completing permission application, publish application to enterprise
133+
- Record the app's `Client ID` and `Client Secret`
134+
135+
### Permission Description
136+
137+
- **`drive:drive`**: This is the core permission for accessing cloud documents, allowing the app to read user's documents, spreadsheets, slides, and other files
138+
- **`space:document:retrieve`**: Used to access documents in knowledge bases and spaces, expanding document access scope
139+
- **`offline_access`**: Allows the app to access resources when user is offline, which is crucial for background sync tasks
140+
61141
## Configuration Architecture
62142

63143
### Connector Level (Fixed Configuration)
@@ -67,10 +147,10 @@ connector:
67147
enabled: true
68148
interval: "30s"
69149
page_size: 100
70-
oauth:
150+
o_auth_config:
71151
auth_url: "https://accounts.feishu.cn/open-apis/authen/v1/authorize"
72152
token_url: "https://open.feishu.cn/open-apis/authen/v2/oauth/token"
73-
redirect_uri: "/connector/feishu/oauth_redirect"
153+
redirect_uri: "/connector/feishu/oauth_redirect" # Dynamically built, supports multi-environment
74154
```
75155
76156
### Datasource Level (User Configuration)
@@ -175,7 +255,8 @@ curl -H 'Content-Type: application/json' -XPOST "http://localhost:9000/datasourc
175255
|-------|------|-------------|--------|
176256
| `access_token` | string | Access token for API calls | Automatically obtained via OAuth |
177257
| `refresh_token` | string | Refresh token for token updates | Automatically obtained via OAuth |
178-
| `token_expiry` | string | Token expiration time (RFC3339 format) | Automatically obtained via OAuth |
258+
| `token_expiry` | string | Access token expiration time (RFC3339 format) | Automatically obtained via OAuth |
259+
| `refresh_token_expiry` | string | Refresh token expiration time (RFC3339 format) | Automatically obtained via OAuth |
179260
| `profile` | object | User information (ID, name, email, etc.) | Automatically obtained via OAuth |
180261

181262
### Sync Configuration
@@ -205,7 +286,10 @@ The Feishu connector supports the following cloud document types:
205286

206287
#### Step 1: Create Feishu App
207288
1. Visit [Feishu Open Platform](https://open.feishu.cn/)
208-
2. Create a new app, apply for `drive:read` permission
289+
2. Create a new app, apply for the following permissions:
290+
- **`drive:drive`** - Cloud document access permission
291+
- **`space:document:retrieve`** - Knowledge base document retrieval permission
292+
- **`offline_access`** - Offline access permission
209293
3. Record the app's `Client ID` and `Client Secret`
210294

211295
#### Step 2: Create Datasource
@@ -217,7 +301,7 @@ The Feishu connector supports the following cloud document types:
217301
1. Click "Connect" button
218302
2. System redirects to Feishu authorization page
219303
3. User completes authorization
220-
4. System automatically updates datasource with OAuth token information
304+
4. System automatically updates datasource with OAuth token information and expiration times
221305

222306
### Method 2: User Access Token
223307

@@ -242,6 +326,13 @@ The Feishu connector supports the following cloud document types:
242326
- `GET /connector/feishu/connect` - OAuth authorization request
243327
- `GET /connector/feishu/oauth_redirect` - OAuth callback processing
244328
- **Authentication Requirements**: All OAuth endpoints require user login
329+
- **Scope Configuration**: Uses `drive:drive space:document:retrieve offline_access` permission scope
330+
331+
### Token Lifecycle Management
332+
- **Auto-refresh**: Automatically refreshes access_token when expired using refresh_token
333+
- **Expiration Checking**: Checks expiration times for both access_token and refresh_token
334+
- **Smart Handling**: Stops synchronization and logs errors if both tokens are expired
335+
- **Data Persistence**: Automatically saves refreshed token information to datasource configuration
245336

246337
### Special Type Processing
247338

@@ -251,9 +342,12 @@ The connector automatically searches folder contents recursively, ensuring all d
251342
## Important Notes
252343

253344
1. **Authentication Method Selection**: You must choose either OAuth authentication or user access token authentication, they cannot be used simultaneously
254-
2. **OAuth Recommended**: OAuth authentication is recommended for higher security and automatic token refresh support
345+
2. **OAuth Recommended**: OAuth authentication is recommended for higher security, automatic token refresh, and expiration time management
255346
3. **Token Management**: When using user access tokens, manual token expiration management is required
256-
4. **Permission Requirements**: Feishu apps need `drive:read` permission to access cloud documents
347+
4. **Permission Requirements**: Feishu apps need to apply for and obtain the following permissions:
348+
- `drive:drive` - Cloud document access permission
349+
- `space:document:retrieve` - Knowledge base retrieval permission
350+
- `offline_access` - Offline access permission
257351
5. **API Limits**: Pay attention to Feishu API call frequency limits
258352

259353
## Troubleshooting
@@ -262,13 +356,33 @@ The connector automatically searches folder contents recursively, ensuring all d
262356

263357
1. **Authentication Failure**
264358
- Check if `client_id` and `client_secret` are correct
265-
- Confirm if Feishu app has `drive:read` permission
359+
- Confirm if Feishu app has applied for and obtained the following permissions:
360+
- `drive:drive` - Cloud document access permission
361+
- `space:document:retrieve` - Knowledge base retrieval permission
362+
- `offline_access` - Offline access permission
363+
- Check OAuth redirect URI configuration
364+
- Confirm if application has been published to enterprise
266365

267366
2. **Token Expiration**
268-
- OAuth Authentication: System automatically refreshes tokens
367+
- OAuth Authentication: System automatically refreshes tokens, check if refresh_token is also expired
269368
- User Access Token: Manual token updates required
270369

271370
3. **Sync Failure**
272371
- Check network connectivity
273372
- Confirm if token is valid
274373
- View system logs for detailed error information
374+
- Check expiration times for both tokens
375+
376+
4. **OAuth Redirect Errors**
377+
- Confirm redirect URI in application configuration
378+
- Check if network environment supports dynamic URI construction
379+
- View redirect URI construction process in system logs
380+
381+
### Log Debugging
382+
The connector provides detailed logging, including:
383+
- Each step of the OAuth flow
384+
- Token refresh process
385+
- Expiration time checking
386+
- Error details and stack information
387+
388+
Use logs to quickly locate and resolve issues.

0 commit comments

Comments
 (0)