matimo 0.1.0-alpha.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.
- package/LICENSE +21 -0
- package/README.md +651 -0
- package/dist/auth/oauth2-config.d.ts +104 -0
- package/dist/auth/oauth2-config.d.ts.map +1 -0
- package/dist/auth/oauth2-config.js +38 -0
- package/dist/auth/oauth2-config.js.map +1 -0
- package/dist/auth/oauth2-handler.d.ts +130 -0
- package/dist/auth/oauth2-handler.d.ts.map +1 -0
- package/dist/auth/oauth2-handler.js +265 -0
- package/dist/auth/oauth2-handler.js.map +1 -0
- package/dist/auth/oauth2-provider-loader.d.ts +68 -0
- package/dist/auth/oauth2-provider-loader.d.ts.map +1 -0
- package/dist/auth/oauth2-provider-loader.js +120 -0
- package/dist/auth/oauth2-provider-loader.js.map +1 -0
- package/dist/core/schema.d.ts +238 -0
- package/dist/core/schema.d.ts.map +1 -0
- package/dist/core/schema.js +168 -0
- package/dist/core/schema.js.map +1 -0
- package/dist/core/tool-loader.d.ts +29 -0
- package/dist/core/tool-loader.d.ts.map +1 -0
- package/dist/core/tool-loader.js +98 -0
- package/dist/core/tool-loader.js.map +1 -0
- package/dist/core/tool-registry.d.ts +48 -0
- package/dist/core/tool-registry.d.ts.map +1 -0
- package/dist/core/tool-registry.js +89 -0
- package/dist/core/tool-registry.js.map +1 -0
- package/dist/core/types.d.ts +143 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/core/types.js +5 -0
- package/dist/core/types.js.map +1 -0
- package/dist/decorators/index.d.ts +2 -0
- package/dist/decorators/index.d.ts.map +1 -0
- package/dist/decorators/index.js +2 -0
- package/dist/decorators/index.js.map +1 -0
- package/dist/decorators/tool-decorator.d.ts +97 -0
- package/dist/decorators/tool-decorator.d.ts.map +1 -0
- package/dist/decorators/tool-decorator.js +154 -0
- package/dist/decorators/tool-decorator.js.map +1 -0
- package/dist/encodings/parameter-encoding.d.ts +51 -0
- package/dist/encodings/parameter-encoding.d.ts.map +1 -0
- package/dist/encodings/parameter-encoding.js +116 -0
- package/dist/encodings/parameter-encoding.js.map +1 -0
- package/dist/errors/matimo-error.d.ts +34 -0
- package/dist/errors/matimo-error.d.ts.map +1 -0
- package/dist/errors/matimo-error.js +49 -0
- package/dist/errors/matimo-error.js.map +1 -0
- package/dist/executors/command-executor.d.ts +19 -0
- package/dist/executors/command-executor.d.ts.map +1 -0
- package/dist/executors/command-executor.js +94 -0
- package/dist/executors/command-executor.js.map +1 -0
- package/dist/executors/http-executor.d.ts +26 -0
- package/dist/executors/http-executor.d.ts.map +1 -0
- package/dist/executors/http-executor.js +133 -0
- package/dist/executors/http-executor.js.map +1 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +23 -0
- package/dist/index.js.map +1 -0
- package/dist/matimo-instance.d.ts +98 -0
- package/dist/matimo-instance.d.ts.map +1 -0
- package/dist/matimo-instance.js +260 -0
- package/dist/matimo-instance.js.map +1 -0
- package/docs/Gemfile +5 -0
- package/docs/RELEASES.md +69 -0
- package/docs/ROADMAP.md +138 -0
- package/docs/_config.yml +27 -0
- package/docs/api-reference/ERRORS.md +445 -0
- package/docs/api-reference/SDK.md +582 -0
- package/docs/api-reference/TYPES.md +415 -0
- package/docs/architecture/OAUTH.md +1366 -0
- package/docs/architecture/OVERVIEW.md +564 -0
- package/docs/assets/logo.png +0 -0
- package/docs/community/COMMIT_GUIDELINES.md +552 -0
- package/docs/framework-integrations/LANGCHAIN.md +286 -0
- package/docs/getting-started/QUICK_START.md +211 -0
- package/docs/getting-started/YOUR_FIRST_TOOL.md +217 -0
- package/docs/getting-started/installation.md +124 -0
- package/docs/index.md +288 -0
- package/docs/tool-development/DECORATOR_GUIDE.md +633 -0
- package/docs/tool-development/OAUTH_LINK.md +5 -0
- package/docs/tool-development/PROVIDER_CONFIGURATION.md +458 -0
- package/docs/tool-development/TESTING.md +412 -0
- package/docs/tool-development/TOOL_SPECIFICATION.md +793 -0
- package/docs/tool-development/YAML_TOOLS.md +65 -0
- package/docs/troubleshooting/FAQ.md +391 -0
- package/docs/user-guide/AUTHENTICATION.md +255 -0
- package/docs/user-guide/DEVELOPMENT_STANDARDS.md +698 -0
- package/docs/user-guide/SDK_PATTERNS.md +316 -0
- package/docs/user-guide/TOOL_DISCOVERY.md +209 -0
- package/package.json +96 -0
|
@@ -0,0 +1,458 @@
|
|
|
1
|
+
# Provider Configuration Guide
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
Matimo uses a **configuration-driven** approach to OAuth2 provider endpoints. Instead of hardcoding provider information into the application, all provider definitions are stored in **YAML files**. This enables:
|
|
6
|
+
|
|
7
|
+
- ✅ Support for **infinite providers** without code changes
|
|
8
|
+
- ✅ **Configuration-driven design** - no coupling between code and provider endpoints
|
|
9
|
+
- ✅ **Easy customization** - override endpoints via environment variables or runtime config
|
|
10
|
+
- ✅ **Zero code modifications** - users can add new providers just by creating YAML files
|
|
11
|
+
|
|
12
|
+
## Provider Definition Structure
|
|
13
|
+
|
|
14
|
+
Each OAuth2 provider must have a `definition.yaml` file in its provider folder:
|
|
15
|
+
|
|
16
|
+
```
|
|
17
|
+
tools/
|
|
18
|
+
├── gmail/
|
|
19
|
+
│ └── definition.yaml ← Provider definition
|
|
20
|
+
├── github/
|
|
21
|
+
│ └── definition.yaml
|
|
22
|
+
├── slack/
|
|
23
|
+
│ └── definition.yaml
|
|
24
|
+
└── [your-provider]/
|
|
25
|
+
└── definition.yaml
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
### Provider Definition Format
|
|
29
|
+
|
|
30
|
+
```yaml
|
|
31
|
+
name: google-provider # Unique name for this provider definition
|
|
32
|
+
type: provider # MUST be "provider" to indicate this is an OAuth2 config
|
|
33
|
+
version: '1.0.0' # Semantic version of the provider config
|
|
34
|
+
description: Google OAuth2 provider # Optional description
|
|
35
|
+
|
|
36
|
+
provider:
|
|
37
|
+
name: google # Provider identifier (used in code)
|
|
38
|
+
displayName: Google # Human-readable name
|
|
39
|
+
|
|
40
|
+
endpoints:
|
|
41
|
+
authorizationUrl: https://accounts.google.com/o/oauth2/v2/auth
|
|
42
|
+
tokenUrl: https://oauth2.googleapis.com/token
|
|
43
|
+
revokeUrl: https://oauth2.googleapis.com/revoke # Optional
|
|
44
|
+
|
|
45
|
+
defaultScopes: # Optional default scopes
|
|
46
|
+
- https://www.googleapis.com/auth/gmail.send
|
|
47
|
+
- https://www.googleapis.com/auth/gmail.readonly
|
|
48
|
+
|
|
49
|
+
documentation: https://developers.google.com/identity/protocols/oauth2
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Configuration Priority
|
|
53
|
+
|
|
54
|
+
Matimo resolves OAuth2 endpoints using a **3-tier priority system**:
|
|
55
|
+
|
|
56
|
+
### 1. Runtime Configuration (Highest Priority)
|
|
57
|
+
User provides endpoints directly in code:
|
|
58
|
+
|
|
59
|
+
```typescript
|
|
60
|
+
const oauth2 = new OAuth2Handler({
|
|
61
|
+
provider: 'google',
|
|
62
|
+
clientId: '...',
|
|
63
|
+
clientSecret: '...',
|
|
64
|
+
redirectUri: '...',
|
|
65
|
+
endpoints: { // ← These override everything else
|
|
66
|
+
authorizationUrl: 'https://custom.company.com/auth',
|
|
67
|
+
tokenUrl: 'https://custom.company.com/token',
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
**Use case:** Custom or internal OAuth2 servers
|
|
73
|
+
|
|
74
|
+
### 2. Environment Variables (Medium Priority)
|
|
75
|
+
Deploy-time configuration via environment variables:
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
export OAUTH_GOOGLE_AUTH_URL=https://custom.company.com/auth
|
|
79
|
+
export OAUTH_GOOGLE_TOKEN_URL=https://custom.company.com/token
|
|
80
|
+
export OAUTH_GOOGLE_REVOKE_URL=https://custom.company.com/revoke
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
**Use case:** Different endpoints per deployment (dev, staging, prod)
|
|
84
|
+
|
|
85
|
+
### 3. YAML Configuration (Default)
|
|
86
|
+
Default endpoints defined in `tools/[provider]/definition.yaml`:
|
|
87
|
+
|
|
88
|
+
```yaml
|
|
89
|
+
provider:
|
|
90
|
+
endpoints:
|
|
91
|
+
authorizationUrl: https://accounts.google.com/o/oauth2/v2/auth
|
|
92
|
+
tokenUrl: https://oauth2.googleapis.com/token
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
**Use case:** Standard provider defaults
|
|
96
|
+
|
|
97
|
+
### Resolution Example
|
|
98
|
+
|
|
99
|
+
```typescript
|
|
100
|
+
// If config.endpoints is provided → Use that (Priority 1)
|
|
101
|
+
const handler = new OAuth2Handler({
|
|
102
|
+
provider: 'google',
|
|
103
|
+
clientId: '...',
|
|
104
|
+
endpoints: { authorizationUrl: 'https://custom/auth', ... } // ← Used
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
// Else if OAUTH_GOOGLE_AUTH_URL env var is set → Use that (Priority 2)
|
|
108
|
+
process.env.OAUTH_GOOGLE_AUTH_URL = 'https://custom/auth';
|
|
109
|
+
const handler = new OAuth2Handler({
|
|
110
|
+
provider: 'google',
|
|
111
|
+
clientId: '...',
|
|
112
|
+
// No endpoints provided, env var checked
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
// Else use tools/google/definition.yaml (Priority 3)
|
|
116
|
+
const handler = new OAuth2Handler({
|
|
117
|
+
provider: 'google',
|
|
118
|
+
clientId: '...',
|
|
119
|
+
// No endpoints or env vars, loads from YAML
|
|
120
|
+
});
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
## Adding a New Provider
|
|
124
|
+
|
|
125
|
+
### Step 1: Create Provider Definition File
|
|
126
|
+
|
|
127
|
+
Create `tools/[provider-name]/definition.yaml`:
|
|
128
|
+
|
|
129
|
+
```yaml
|
|
130
|
+
name: microsoft-provider
|
|
131
|
+
type: provider
|
|
132
|
+
version: '1.0.0'
|
|
133
|
+
description: Microsoft Azure AD OAuth2 provider
|
|
134
|
+
|
|
135
|
+
provider:
|
|
136
|
+
name: microsoft
|
|
137
|
+
displayName: Microsoft
|
|
138
|
+
|
|
139
|
+
endpoints:
|
|
140
|
+
authorizationUrl: https://login.microsoftonline.com/common/oauth2/v2.0/authorize
|
|
141
|
+
tokenUrl: https://login.microsoftonline.com/common/oauth2/v2.0/token
|
|
142
|
+
revokeUrl: https://login.microsoftonline.com/common/oauth2/v2.0/token/revoke
|
|
143
|
+
|
|
144
|
+
defaultScopes:
|
|
145
|
+
- https://graph.microsoft.com/Mail.Send
|
|
146
|
+
- https://graph.microsoft.com/user.read
|
|
147
|
+
|
|
148
|
+
documentation: https://docs.microsoft.com/en-us/azure/active-directory/develop/v2-oauth2-auth-code-flow
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
### Step 2: Use in Code
|
|
152
|
+
|
|
153
|
+
The provider loader automatically discovers the provider:
|
|
154
|
+
|
|
155
|
+
```typescript
|
|
156
|
+
import { OAuth2Handler } from '@matimo/oauth2';
|
|
157
|
+
|
|
158
|
+
const oauth2 = new OAuth2Handler({
|
|
159
|
+
provider: 'microsoft', // Provider name from definition.yaml
|
|
160
|
+
clientId: process.env.MICROSOFT_CLIENT_ID,
|
|
161
|
+
clientSecret: process.env.MICROSOFT_CLIENT_SECRET,
|
|
162
|
+
redirectUri: 'http://localhost:3000/callback',
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
// Get authorization URL
|
|
166
|
+
const authUrl = oauth2.getAuthorizationUrl({
|
|
167
|
+
scopes: ['https://graph.microsoft.com/Mail.Send'],
|
|
168
|
+
userId: 'user-123',
|
|
169
|
+
});
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
### Step 3: (Optional) Override with Environment Variables
|
|
173
|
+
|
|
174
|
+
For deployment-specific endpoints:
|
|
175
|
+
|
|
176
|
+
```bash
|
|
177
|
+
export OAUTH_MICROSOFT_AUTH_URL=https://custom-idp.company.com/authorize
|
|
178
|
+
export OAUTH_MICROSOFT_TOKEN_URL=https://custom-idp.company.com/token
|
|
179
|
+
export OAUTH_MICROSOFT_REVOKE_URL=https://custom-idp.company.com/revoke
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
## Built-in Provider Examples
|
|
183
|
+
|
|
184
|
+
### Google (Gmail)
|
|
185
|
+
|
|
186
|
+
**File:** `tools/gmail/definition.yaml`
|
|
187
|
+
|
|
188
|
+
```yaml
|
|
189
|
+
name: google-provider
|
|
190
|
+
type: provider
|
|
191
|
+
version: '1.0.0'
|
|
192
|
+
|
|
193
|
+
provider:
|
|
194
|
+
name: google
|
|
195
|
+
displayName: Google
|
|
196
|
+
|
|
197
|
+
endpoints:
|
|
198
|
+
authorizationUrl: https://accounts.google.com/o/oauth2/v2/auth
|
|
199
|
+
tokenUrl: https://oauth2.googleapis.com/token
|
|
200
|
+
revokeUrl: https://oauth2.googleapis.com/revoke
|
|
201
|
+
|
|
202
|
+
defaultScopes:
|
|
203
|
+
- https://www.googleapis.com/auth/gmail.send
|
|
204
|
+
- https://www.googleapis.com/auth/gmail.readonly
|
|
205
|
+
- https://www.googleapis.com/auth/gmail.compose
|
|
206
|
+
|
|
207
|
+
documentation: https://developers.google.com/identity/protocols/oauth2
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
### GitHub
|
|
211
|
+
|
|
212
|
+
**File:** `tools/github/definition.yaml`
|
|
213
|
+
|
|
214
|
+
```yaml
|
|
215
|
+
name: github-provider
|
|
216
|
+
type: provider
|
|
217
|
+
version: '1.0.0'
|
|
218
|
+
|
|
219
|
+
provider:
|
|
220
|
+
name: github
|
|
221
|
+
displayName: GitHub
|
|
222
|
+
|
|
223
|
+
endpoints:
|
|
224
|
+
authorizationUrl: https://github.com/login/oauth/authorize
|
|
225
|
+
tokenUrl: https://github.com/login/oauth/access_token
|
|
226
|
+
|
|
227
|
+
defaultScopes:
|
|
228
|
+
- user:email
|
|
229
|
+
- repo
|
|
230
|
+
- gist
|
|
231
|
+
|
|
232
|
+
documentation: https://docs.github.com/en/developers/apps/building-oauth-apps
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
### Slack
|
|
236
|
+
|
|
237
|
+
**File:** `tools/slack/definition.yaml`
|
|
238
|
+
|
|
239
|
+
```yaml
|
|
240
|
+
name: slack-provider
|
|
241
|
+
type: provider
|
|
242
|
+
version: '1.0.0'
|
|
243
|
+
|
|
244
|
+
provider:
|
|
245
|
+
name: slack
|
|
246
|
+
displayName: Slack
|
|
247
|
+
|
|
248
|
+
endpoints:
|
|
249
|
+
authorizationUrl: https://slack.com/oauth/v2/authorize
|
|
250
|
+
tokenUrl: https://slack.com/api/oauth.v2.access
|
|
251
|
+
|
|
252
|
+
defaultScopes:
|
|
253
|
+
- chat:write
|
|
254
|
+
- channels:read
|
|
255
|
+
- users:read
|
|
256
|
+
|
|
257
|
+
documentation: https://api.slack.com/authentication/oauth-v2
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
## Token Management
|
|
261
|
+
|
|
262
|
+
Matimo handles OAuth2 flows but **does NOT store tokens**. Token storage is your responsibility:
|
|
263
|
+
|
|
264
|
+
```typescript
|
|
265
|
+
import { OAuth2Handler } from '@matimo/oauth2';
|
|
266
|
+
|
|
267
|
+
// 1. Initialize handler
|
|
268
|
+
const oauth2 = new OAuth2Handler({
|
|
269
|
+
provider: 'google',
|
|
270
|
+
clientId: '...',
|
|
271
|
+
clientSecret: '...',
|
|
272
|
+
redirectUri: 'http://localhost:3000/callback',
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
// 2. Generate auth URL
|
|
276
|
+
const authUrl = oauth2.getAuthorizationUrl({
|
|
277
|
+
scopes: ['https://www.googleapis.com/auth/gmail.send'],
|
|
278
|
+
userId: 'user-123',
|
|
279
|
+
});
|
|
280
|
+
// → Redirect user to authUrl
|
|
281
|
+
|
|
282
|
+
// 3. Exchange code for token
|
|
283
|
+
const token = await oauth2.exchangeCodeForToken('user-123', authCode);
|
|
284
|
+
// Result: { accessToken, refreshToken, expiresAt, ... }
|
|
285
|
+
|
|
286
|
+
// 4. YOU store the token (database, Redis, file, etc.)
|
|
287
|
+
await database.saveToken('user-123', token);
|
|
288
|
+
|
|
289
|
+
// 5. Later, retrieve and use the token with Matimo tools
|
|
290
|
+
const stored = await database.getToken('user-123');
|
|
291
|
+
await matimo.execute('gmail-send-email', {
|
|
292
|
+
to: 'recipient@example.com',
|
|
293
|
+
GMAIL_ACCESS_TOKEN: stored.accessToken, // ← Pass token here
|
|
294
|
+
});
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
## Dynamic Provider Discovery
|
|
298
|
+
|
|
299
|
+
The provider loader automatically discovers all providers from YAML files:
|
|
300
|
+
|
|
301
|
+
```typescript
|
|
302
|
+
import { OAuth2ProviderLoader } from '@matimo/auth';
|
|
303
|
+
|
|
304
|
+
const loader = new OAuth2ProviderLoader('./tools');
|
|
305
|
+
const providers = await loader.loadProviders();
|
|
306
|
+
|
|
307
|
+
// List all discovered providers
|
|
308
|
+
const providerNames = providers.keys();
|
|
309
|
+
// Output: ['google', 'github', 'slack', 'microsoft', ...]
|
|
310
|
+
|
|
311
|
+
// Get endpoints for specific provider
|
|
312
|
+
const googleEndpoints = providers.get('google');
|
|
313
|
+
console.log(googleEndpoints);
|
|
314
|
+
// Output: {
|
|
315
|
+
// authorizationUrl: 'https://accounts.google.com/...',
|
|
316
|
+
// tokenUrl: 'https://oauth2.googleapis.com/token',
|
|
317
|
+
// revokeUrl: '...'
|
|
318
|
+
// }
|
|
319
|
+
```
|
|
320
|
+
|
|
321
|
+
## Custom OAuth2 Server
|
|
322
|
+
|
|
323
|
+
Use runtime configuration to connect to a custom OAuth2 server:
|
|
324
|
+
|
|
325
|
+
```typescript
|
|
326
|
+
const oauth2 = new OAuth2Handler({
|
|
327
|
+
provider: 'internal-oauth', // Any name
|
|
328
|
+
clientId: 'internal-client',
|
|
329
|
+
clientSecret: 'internal-secret',
|
|
330
|
+
redirectUri: 'http://localhost:3000/callback',
|
|
331
|
+
endpoints: {
|
|
332
|
+
authorizationUrl: 'https://oauth.company.internal/authorize',
|
|
333
|
+
tokenUrl: 'https://oauth.company.internal/token',
|
|
334
|
+
revokeUrl: 'https://oauth.company.internal/revoke',
|
|
335
|
+
}
|
|
336
|
+
});
|
|
337
|
+
```
|
|
338
|
+
|
|
339
|
+
Or use environment variables:
|
|
340
|
+
|
|
341
|
+
```bash
|
|
342
|
+
export OAUTH_INTERNAL_AUTH_URL=https://oauth.company.internal/authorize
|
|
343
|
+
export OAUTH_INTERNAL_TOKEN_URL=https://oauth.company.internal/token
|
|
344
|
+
export OAUTH_INTERNAL_REVOKE_URL=https://oauth.company.internal/revoke
|
|
345
|
+
```
|
|
346
|
+
|
|
347
|
+
```typescript
|
|
348
|
+
const oauth2 = new OAuth2Handler({
|
|
349
|
+
provider: 'internal',
|
|
350
|
+
clientId: '...',
|
|
351
|
+
clientSecret: '...',
|
|
352
|
+
redirectUri: '...',
|
|
353
|
+
// Endpoints loaded from env vars automatically
|
|
354
|
+
});
|
|
355
|
+
```
|
|
356
|
+
|
|
357
|
+
## Best Practices
|
|
358
|
+
|
|
359
|
+
### 1. Use Configuration-Driven Approach
|
|
360
|
+
❌ Don't hardcode endpoints:
|
|
361
|
+
```typescript
|
|
362
|
+
const oauth2 = new OAuth2Handler({
|
|
363
|
+
provider: 'custom',
|
|
364
|
+
clientId: '...',
|
|
365
|
+
endpoints: {
|
|
366
|
+
authorizationUrl: 'https://hardcoded.example.com/auth', // ❌ Bad
|
|
367
|
+
}
|
|
368
|
+
});
|
|
369
|
+
```
|
|
370
|
+
|
|
371
|
+
✅ Use YAML or environment variables:
|
|
372
|
+
```yaml
|
|
373
|
+
# tools/custom/definition.yaml
|
|
374
|
+
provider:
|
|
375
|
+
endpoints:
|
|
376
|
+
authorizationUrl: https://custom.example.com/auth
|
|
377
|
+
```
|
|
378
|
+
|
|
379
|
+
### 2. Document Provider Requirements
|
|
380
|
+
Include setup instructions in provider definition:
|
|
381
|
+
|
|
382
|
+
```yaml
|
|
383
|
+
provider:
|
|
384
|
+
documentation: https://docs.example.com/oauth2-setup
|
|
385
|
+
# Include links to:
|
|
386
|
+
# - How to register OAuth app
|
|
387
|
+
# - Where to get client ID/secret
|
|
388
|
+
# - Required scopes for different use cases
|
|
389
|
+
```
|
|
390
|
+
|
|
391
|
+
### 3. Use Semantic Versioning
|
|
392
|
+
Update version when endpoints change:
|
|
393
|
+
|
|
394
|
+
```yaml
|
|
395
|
+
version: '1.1.0' # Increment for breaking changes
|
|
396
|
+
```
|
|
397
|
+
|
|
398
|
+
### 4. Never Hardcode Secrets
|
|
399
|
+
Always use environment variables:
|
|
400
|
+
|
|
401
|
+
```typescript
|
|
402
|
+
const oauth2 = new OAuth2Handler({
|
|
403
|
+
provider: 'google',
|
|
404
|
+
clientId: process.env.GOOGLE_CLIENT_ID, // ✅ From env vars
|
|
405
|
+
clientSecret: process.env.GOOGLE_CLIENT_SECRET, // ✅ From env vars
|
|
406
|
+
redirectUri: process.env.GOOGLE_REDIRECT_URI, // ✅ From env vars
|
|
407
|
+
});
|
|
408
|
+
```
|
|
409
|
+
|
|
410
|
+
### 5. Validate Provider Definition
|
|
411
|
+
Matimo automatically validates YAML structure:
|
|
412
|
+
|
|
413
|
+
```typescript
|
|
414
|
+
// This throws MatimoError if definition is invalid
|
|
415
|
+
const loader = new OAuth2ProviderLoader('./tools');
|
|
416
|
+
await loader.loadProviders();
|
|
417
|
+
```
|
|
418
|
+
|
|
419
|
+
## Troubleshooting
|
|
420
|
+
|
|
421
|
+
### Provider Not Found
|
|
422
|
+
```
|
|
423
|
+
MatimoError: Unsupported OAuth2 provider: custom. Provide endpoints via:
|
|
424
|
+
1. config.endpoints (runtime override)
|
|
425
|
+
2. OAUTH_CUSTOM_AUTH_URL env var (deployment config)
|
|
426
|
+
3. tools/custom/definition.yaml (YAML configuration)
|
|
427
|
+
```
|
|
428
|
+
|
|
429
|
+
**Solution:** Create `tools/custom/definition.yaml` with provider definition
|
|
430
|
+
|
|
431
|
+
### Invalid Provider Definition
|
|
432
|
+
```
|
|
433
|
+
MatimoError: Invalid provider definition: Missing required field 'endpoints'
|
|
434
|
+
```
|
|
435
|
+
|
|
436
|
+
**Solution:** Ensure YAML has required fields:
|
|
437
|
+
- `name`
|
|
438
|
+
- `type: provider`
|
|
439
|
+
- `provider.endpoints.authorizationUrl`
|
|
440
|
+
- `provider.endpoints.tokenUrl`
|
|
441
|
+
|
|
442
|
+
### Environment Variable Not Read
|
|
443
|
+
Make sure env var name matches the pattern:
|
|
444
|
+
```bash
|
|
445
|
+
# For provider: 'google'
|
|
446
|
+
export OAUTH_GOOGLE_AUTH_URL=...
|
|
447
|
+
export OAUTH_GOOGLE_TOKEN_URL=...
|
|
448
|
+
export OAUTH_GOOGLE_REVOKE_URL=... # Optional
|
|
449
|
+
|
|
450
|
+
# For provider: 'microsoft'
|
|
451
|
+
export OAUTH_MICROSOFT_AUTH_URL=...
|
|
452
|
+
```
|
|
453
|
+
|
|
454
|
+
## See Also
|
|
455
|
+
|
|
456
|
+
- [OAuth2Handler API](./src/auth/oauth2-handler.ts)
|
|
457
|
+
- [Provider Loader Implementation](./src/auth/oauth2-provider-loader.ts)
|
|
458
|
+
- [Integration Examples](./test/integration/)
|