@simpleapps-com/augur-api 0.2.6 → 0.2.8
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/API-DISCOVERY.md +255 -0
- package/AUTHENTICATION.md +371 -0
- package/QUICKSTART.md +352 -0
- package/README.md +392 -175
- package/dist/cjs/index.d.ts +1 -1
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/services/commerce/client.d.ts +222 -18
- package/dist/cjs/services/commerce/client.d.ts.map +1 -1
- package/dist/cjs/services/commerce/client.js +156 -17
- package/dist/cjs/services/commerce/client.js.map +1 -1
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/services/commerce/client.d.ts +222 -18
- package/dist/esm/services/commerce/client.d.ts.map +1 -1
- package/dist/esm/services/commerce/client.js +156 -17
- package/dist/esm/services/commerce/client.js.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/services/commerce/client.d.ts +222 -18
- package/dist/types/services/commerce/client.d.ts.map +1 -1
- package/package.json +5 -2
package/API-DISCOVERY.md
ADDED
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
# AI-Powered Discovery: Code That Almost Writes Itself
|
|
2
|
+
|
|
3
|
+
Transform API exploration from documentation hunting into natural language conversation with intelligent business context understanding.
|
|
4
|
+
|
|
5
|
+
## The Discovery Revolution
|
|
6
|
+
|
|
7
|
+
Never memorize endpoints again. Ask for business functionality and let the platform's intelligence find everything you need:
|
|
8
|
+
|
|
9
|
+
```typescript
|
|
10
|
+
import { AugurAPI } from '@simpleapps-com/augur-api';
|
|
11
|
+
|
|
12
|
+
const api = AugurAPI.fromContext(context);
|
|
13
|
+
|
|
14
|
+
// Business intent discovery - no technical knowledge required
|
|
15
|
+
const customerOps = await api.findEndpoint('customer lifecycle management');
|
|
16
|
+
const inventoryFlow = await api.findEndpoint('supply chain optimization');
|
|
17
|
+
const ecommerceJourney = await api.findEndpoint('online shopping experience');
|
|
18
|
+
|
|
19
|
+
// Platform reveals complete business workflows
|
|
20
|
+
const services = await api.discover();
|
|
21
|
+
console.log(`🚀 ${services.length} intelligent business services available`);
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Semantic Intelligence Engine
|
|
25
|
+
|
|
26
|
+
### Business Context Understanding
|
|
27
|
+
|
|
28
|
+
The discovery system doesn't just match keywords - it understands business processes:
|
|
29
|
+
|
|
30
|
+
```typescript
|
|
31
|
+
// Ask about business outcomes, not technical endpoints
|
|
32
|
+
const results = await api.findEndpoint('customer satisfaction analytics');
|
|
33
|
+
// Intelligently maps to:
|
|
34
|
+
// - api.customers.customer.get (customer profiles)
|
|
35
|
+
// - api.orders.orders.lookup (purchase history)
|
|
36
|
+
// - api.p21Pim.items.suggestWebDescription (product experience)
|
|
37
|
+
|
|
38
|
+
const qualityControl = await api.findEndpoint('inventory quality assurance');
|
|
39
|
+
// Discovers:
|
|
40
|
+
// - api.vmi.inventory.checkAvailability (stock validation)
|
|
41
|
+
// - api.vmi.warehouses.list (distribution quality)
|
|
42
|
+
// - api.nexus.binTransfers.list (movement tracking)
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### Cross-Service Workflow Intelligence
|
|
46
|
+
|
|
47
|
+
The platform maps relationships across all 13 microservices:
|
|
48
|
+
|
|
49
|
+
```typescript
|
|
50
|
+
// Working with users? Platform suggests customer operations
|
|
51
|
+
const userWorkflow = await api.findEndpoint('user account management');
|
|
52
|
+
// Reveals connected workflow:
|
|
53
|
+
// 1. Authentication: api.joomla.users.verifyPassword
|
|
54
|
+
// 2. Profile creation: api.customers.customer.create
|
|
55
|
+
// 3. Permission setup: api.joomla.userGroups.list
|
|
56
|
+
// 4. Order access: api.orders.salesRep.getOrders
|
|
57
|
+
|
|
58
|
+
// Inventory management reveals pricing connections
|
|
59
|
+
const inventoryOps = await api.findEndpoint('warehouse operations');
|
|
60
|
+
// Platform intelligence connects:
|
|
61
|
+
// 1. Stock levels: api.vmi.inventory.checkAvailability
|
|
62
|
+
// 2. Pricing context: api.pricing.getPrice
|
|
63
|
+
// 3. Product details: api.items.products.get
|
|
64
|
+
// 4. Replenishment: api.vmi.inventory.replenish
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## Advanced Discovery Capabilities
|
|
68
|
+
|
|
69
|
+
### Multi-Dimensional Search
|
|
70
|
+
|
|
71
|
+
The discovery engine uses sophisticated scoring across multiple dimensions:
|
|
72
|
+
|
|
73
|
+
```typescript
|
|
74
|
+
// Natural language with business filters
|
|
75
|
+
const results = await api.findEndpoint('customer service optimization', {
|
|
76
|
+
domain: 'customer-management', // Business domain focus
|
|
77
|
+
readOnly: true, // Query operations only
|
|
78
|
+
minScore: 0.3, // High relevance threshold
|
|
79
|
+
maxResults: 8, // Focused result set
|
|
80
|
+
service: 'customers' // Optional service filter
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
// Rich result context for each match
|
|
84
|
+
results.forEach(result => {
|
|
85
|
+
console.log(`🎯 ${result.endpoint.fullPath} (${result.score.toFixed(2)})`);
|
|
86
|
+
console.log(` Business value: ${result.endpoint.description}`);
|
|
87
|
+
console.log(` Match reason: ${result.matchReason}`);
|
|
88
|
+
console.log(` Related ops: ${result.endpoint.relatedEndpoints.slice(0,3).join(', ')}`);
|
|
89
|
+
console.log(` Workflow: ${result.endpoint.domain}`);
|
|
90
|
+
});
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## Business Intelligence Queries
|
|
94
|
+
|
|
95
|
+
The platform understands complex business scenarios and suggests complete workflows:
|
|
96
|
+
|
|
97
|
+
| Business Intent | Platform Discovery | Workflow Intelligence |
|
|
98
|
+
|----------------|-------------------|---------------------|
|
|
99
|
+
| `'customer lifecycle management'` | User authentication, customer profiles, order history, payment setup | Cross-service customer journey mapping |
|
|
100
|
+
| `'supply chain optimization'` | Inventory levels, warehouse operations, distributor networks, pricing | End-to-end supply chain visibility |
|
|
101
|
+
| `'e-commerce automation'` | Product search, pricing, cart management, checkout, payments | Complete shopping experience workflow |
|
|
102
|
+
| `'content personalization'` | AI content generation, search optimization, user preferences | Intelligent content delivery |
|
|
103
|
+
| `'order fulfillment intelligence'` | Order processing, inventory allocation, payment processing, shipping | Automated fulfillment workflows |
|
|
104
|
+
| `'business analytics integration'` | Customer data, order patterns, inventory metrics, pricing trends | Cross-service business intelligence |
|
|
105
|
+
|
|
106
|
+
## Semantic Discovery Architecture
|
|
107
|
+
|
|
108
|
+
### Rich Metadata Integration
|
|
109
|
+
|
|
110
|
+
Every endpoint includes comprehensive semantic metadata for AI agents:
|
|
111
|
+
|
|
112
|
+
```typescript
|
|
113
|
+
/**
|
|
114
|
+
* @fullPath api.vmi.inventory.checkAvailability
|
|
115
|
+
* @service vmi
|
|
116
|
+
* @domain inventory-management
|
|
117
|
+
* @searchTerms ["inventory", "stock levels", "availability", "warehouse"]
|
|
118
|
+
* @relatedEndpoints ["api.vmi.warehouses.list", "api.pricing.getPrice", "api.items.products.get"]
|
|
119
|
+
* @workflow ["inventory-optimization", "supply-chain-management"]
|
|
120
|
+
* @commonPatterns ["Check product availability", "Validate stock levels", "Inventory monitoring"]
|
|
121
|
+
* @businessRules ["Requires valid warehouse access", "Customer-specific inventory visibility"]
|
|
122
|
+
* @performance "Real-time inventory queries, supports bulk operations"
|
|
123
|
+
*/
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### AI Assistant Integration Excellence
|
|
127
|
+
|
|
128
|
+
When you ask an AI assistant for help, the platform provides complete context:
|
|
129
|
+
|
|
130
|
+
```typescript
|
|
131
|
+
// AI Assistant: "Help me optimize inventory management"
|
|
132
|
+
// Platform provides:
|
|
133
|
+
const inventoryWorkflow = await api.findEndpoint('inventory optimization');
|
|
134
|
+
|
|
135
|
+
// AI receives complete workflow context:
|
|
136
|
+
// 1. Business intent: Supply chain optimization
|
|
137
|
+
// 2. Primary operations: Stock checking, replenishment, distribution
|
|
138
|
+
// 3. Related services: Pricing, product catalog, warehouse management
|
|
139
|
+
// 4. Workflow patterns: Check → Calculate → Order → Track
|
|
140
|
+
// 5. Performance considerations: Real-time vs batch operations
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
## Advanced Business Domain Intelligence
|
|
144
|
+
|
|
145
|
+
### Multi-Service Business Processes
|
|
146
|
+
|
|
147
|
+
The platform maps complete business processes across service boundaries:
|
|
148
|
+
|
|
149
|
+
```typescript
|
|
150
|
+
// E-commerce customer acquisition workflow
|
|
151
|
+
const customerAcquisition = await api.findEndpoint('new customer onboarding');
|
|
152
|
+
// Platform intelligence suggests:
|
|
153
|
+
// Phase 1: Account Creation
|
|
154
|
+
// - api.joomla.users.create (authentication)
|
|
155
|
+
// - api.customers.customer.create (profile)
|
|
156
|
+
// - api.joomla.userGroups.createMapping (permissions)
|
|
157
|
+
// Phase 2: Shopping Setup
|
|
158
|
+
// - api.commerce.cartHeaders.create (shopping cart)
|
|
159
|
+
// - api.payments.unified.transactionSetup (payment method)
|
|
160
|
+
// Phase 3: Product Discovery
|
|
161
|
+
// - api.opensearch.itemSearch.search (product exploration)
|
|
162
|
+
// - api.pricing.getPrice (personalized pricing)
|
|
163
|
+
|
|
164
|
+
// Supply chain workflow intelligence
|
|
165
|
+
const supplyChain = await api.findEndpoint('inventory replenishment automation');
|
|
166
|
+
// Cross-service workflow mapping:
|
|
167
|
+
// Monitor: api.vmi.inventory.checkAvailability
|
|
168
|
+
// Calculate: api.pricing.getPrice (reorder costs)
|
|
169
|
+
// Execute: api.vmi.inventory.replenish
|
|
170
|
+
// Track: api.nexus.binTransfers.list
|
|
171
|
+
// Verify: api.vmi.warehouses.list (distribution status)
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
### Intelligent Search Filtering
|
|
175
|
+
|
|
176
|
+
Advanced filtering that understands business context:
|
|
177
|
+
|
|
178
|
+
```typescript
|
|
179
|
+
// Domain-specific operations
|
|
180
|
+
const customerService = await api.findEndpoint('customer support operations', {
|
|
181
|
+
domain: 'customer-data', // Business domain focus
|
|
182
|
+
readOnly: true, // Query operations only
|
|
183
|
+
minScore: 0.4, // High relevance threshold
|
|
184
|
+
maxResults: 6 // Focused results
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
// Service-specific functionality
|
|
188
|
+
const inventoryMgmt = await api.findEndpoint('warehouse management', {
|
|
189
|
+
service: 'vmi', // VMI service only
|
|
190
|
+
domain: 'inventory-management', // Inventory domain
|
|
191
|
+
minScore: 0.2, // Include broader matches
|
|
192
|
+
maxResults: 12 // Comprehensive results
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
// Workflow-specific operations
|
|
196
|
+
const ecommerceOps = await api.findEndpoint('online shopping', {
|
|
197
|
+
domain: 'e-commerce', // E-commerce domain
|
|
198
|
+
readOnly: false, // Include all operations
|
|
199
|
+
minScore: 0.1, // Cast wide net
|
|
200
|
+
maxResults: 15 // Complete workflow
|
|
201
|
+
});
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
## Platform Discovery Mastery
|
|
205
|
+
|
|
206
|
+
### Complete Service Topology
|
|
207
|
+
|
|
208
|
+
```typescript
|
|
209
|
+
// Comprehensive platform exploration
|
|
210
|
+
const services = await api.discover();
|
|
211
|
+
|
|
212
|
+
// Platform intelligence reveals:
|
|
213
|
+
services.forEach(service => {
|
|
214
|
+
console.log(`🏢 Service: ${service.serviceName}`);
|
|
215
|
+
console.log(` Business domain: ${service.description}`);
|
|
216
|
+
console.log(` Operations available: ${service.endpointCount}`);
|
|
217
|
+
console.log(` Base architecture: ${service.baseUrl}`);
|
|
218
|
+
|
|
219
|
+
// Sample high-value operations
|
|
220
|
+
const topOps = service.endpoints
|
|
221
|
+
.filter(ep => ep.discoverable)
|
|
222
|
+
.slice(0, 3);
|
|
223
|
+
|
|
224
|
+
topOps.forEach(op => {
|
|
225
|
+
console.log(` 🎯 ${op.fullPath}: ${op.description}`);
|
|
226
|
+
});
|
|
227
|
+
});
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
### Business Workflow Discovery
|
|
231
|
+
|
|
232
|
+
```typescript
|
|
233
|
+
// Discover complete business workflows
|
|
234
|
+
const workflows = await Promise.all([
|
|
235
|
+
api.findEndpoint('customer lifecycle'),
|
|
236
|
+
api.findEndpoint('inventory optimization'),
|
|
237
|
+
api.findEndpoint('order fulfillment'),
|
|
238
|
+
api.findEndpoint('content management'),
|
|
239
|
+
api.findEndpoint('financial operations')
|
|
240
|
+
]);
|
|
241
|
+
|
|
242
|
+
// Platform reveals interconnected business processes
|
|
243
|
+
workflows.forEach((workflow, index) => {
|
|
244
|
+
const domains = ['Customer', 'Inventory', 'Orders', 'Content', 'Finance'];
|
|
245
|
+
console.log(`\n${domains[index]} Workflow (${workflow.length} operations):`);
|
|
246
|
+
|
|
247
|
+
workflow.forEach(result => {
|
|
248
|
+
console.log(` 📋 ${result.endpoint.fullPath}`);
|
|
249
|
+
console.log(` Business value: ${result.endpoint.description}`);
|
|
250
|
+
console.log(` Connects to: ${result.endpoint.relatedEndpoints.slice(0,2).join(', ')}`);
|
|
251
|
+
});
|
|
252
|
+
});
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
The discovery system transforms API exploration into business conversation. Describe your business intent, and the platform's intelligence reveals complete workflows across all 13 microservices. No documentation hunting, no endpoint memorization - just natural language business queries that unlock enterprise capability.
|
|
@@ -0,0 +1,371 @@
|
|
|
1
|
+
# Authentication Guide
|
|
2
|
+
|
|
3
|
+
Complete guide to authentication patterns in the Augur API Client.
|
|
4
|
+
|
|
5
|
+
## Standard Authentication (Most Common)
|
|
6
|
+
|
|
7
|
+
The standard authentication pattern works for 95% of use cases.
|
|
8
|
+
|
|
9
|
+
### Dual Authentication System
|
|
10
|
+
|
|
11
|
+
Every API request requires two pieces of authentication:
|
|
12
|
+
|
|
13
|
+
1. **Site ID** (`x-site-id` header) - Identifies which site/tenant you're working with
|
|
14
|
+
2. **Bearer Token** (JWT) - Proves you're authorized to access that site
|
|
15
|
+
|
|
16
|
+
```typescript
|
|
17
|
+
const api = new AugurAPI({
|
|
18
|
+
siteId: 'your-site-id', // Always required
|
|
19
|
+
bearerToken: 'your-jwt-token', // Required except for health checks
|
|
20
|
+
});
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
### How to Get Your Credentials
|
|
24
|
+
|
|
25
|
+
**Site ID**: Usually provided by your system administrator or found in your project configuration.
|
|
26
|
+
|
|
27
|
+
**Bearer Token**: Obtained through your application's login process. This is typically a JWT token that looks like:
|
|
28
|
+
`eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...`
|
|
29
|
+
|
|
30
|
+
### Health Checks (No Authentication Required)
|
|
31
|
+
|
|
32
|
+
Health checks are the only endpoints that don't require a bearer token:
|
|
33
|
+
|
|
34
|
+
```typescript
|
|
35
|
+
// Health checks work without bearer token
|
|
36
|
+
const api = new AugurAPI({
|
|
37
|
+
siteId: 'your-site-id',
|
|
38
|
+
// No bearerToken needed
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
const health = await api.joomla.getHealthCheck();
|
|
42
|
+
const pricingHealth = await api.pricing.getHealthCheck();
|
|
43
|
+
const vmiPing = await api.vmi.health.ping();
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### Dynamic Authentication Updates
|
|
47
|
+
|
|
48
|
+
Update credentials at runtime when needed:
|
|
49
|
+
|
|
50
|
+
```typescript
|
|
51
|
+
// Update token after login/refresh
|
|
52
|
+
api.setAuthToken('new-jwt-token');
|
|
53
|
+
|
|
54
|
+
// Switch to different site
|
|
55
|
+
api.setSiteId('different-site-id');
|
|
56
|
+
|
|
57
|
+
// Example: Token refresh scenario
|
|
58
|
+
async function refreshTokenIfNeeded() {
|
|
59
|
+
try {
|
|
60
|
+
await api.joomla.users.list({ limit: 1 });
|
|
61
|
+
} catch (error) {
|
|
62
|
+
if (error instanceof AuthenticationError) {
|
|
63
|
+
const newToken = await refreshJWTToken();
|
|
64
|
+
api.setAuthToken(newToken);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### Environment Variables Setup
|
|
71
|
+
|
|
72
|
+
Store credentials securely in environment variables:
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
# .env file
|
|
76
|
+
AUGUR_SITE_ID=your-site-id
|
|
77
|
+
AUGUR_JWT_TOKEN=your-jwt-token
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
```typescript
|
|
81
|
+
const api = new AugurAPI({
|
|
82
|
+
siteId: process.env.AUGUR_SITE_ID!,
|
|
83
|
+
bearerToken: process.env.AUGUR_JWT_TOKEN!,
|
|
84
|
+
});
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### Security Best Practices
|
|
88
|
+
|
|
89
|
+
1. **Environment Variables**: Never hardcode credentials
|
|
90
|
+
2. **Token Rotation**: Implement regular token rotation in production
|
|
91
|
+
3. **HTTPS Only**: All API requests use HTTPS in production
|
|
92
|
+
4. **Secure Storage**: Never store tokens in localStorage for web apps
|
|
93
|
+
5. **Minimal Permissions**: Use tokens with minimal required permissions
|
|
94
|
+
|
|
95
|
+
```typescript
|
|
96
|
+
// ✅ Good: Environment-based configuration
|
|
97
|
+
const api = new AugurAPI({
|
|
98
|
+
siteId: process.env.AUGUR_SITE_ID!,
|
|
99
|
+
bearerToken: getSecurelyStoredToken(), // From secure storage
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
// ❌ Bad: Hardcoded credentials
|
|
103
|
+
const api = new AugurAPI({
|
|
104
|
+
siteId: 'hardcoded-site-id',
|
|
105
|
+
bearerToken: 'hardcoded-token', // Never do this!
|
|
106
|
+
});
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
---
|
|
110
|
+
|
|
111
|
+
## Advanced: Cross-Site Authentication
|
|
112
|
+
|
|
113
|
+
**⚠️ Advanced Feature**: Only needed for multi-tenant applications where you need to authenticate users across different sites.
|
|
114
|
+
|
|
115
|
+
### When You Need Cross-Site Auth
|
|
116
|
+
|
|
117
|
+
Cross-site authentication is needed when:
|
|
118
|
+
- You're building a multi-tenant application
|
|
119
|
+
- You need to authenticate a user from one site against a different site
|
|
120
|
+
- You're managing multiple client sites from a central application
|
|
121
|
+
|
|
122
|
+
### Prerequisites
|
|
123
|
+
|
|
124
|
+
- Access to the special `augur_info` site
|
|
125
|
+
- Admin-level JWT token with `augur_info` privileges
|
|
126
|
+
- Target site ID where you want to authenticate the user
|
|
127
|
+
|
|
128
|
+
### Option 1: Streamlined Utility Function (Recommended)
|
|
129
|
+
|
|
130
|
+
```typescript
|
|
131
|
+
import { authenticateUserForSite } from '@simpleapps-com/augur-api';
|
|
132
|
+
|
|
133
|
+
const result = await authenticateUserForSite({
|
|
134
|
+
targetSiteId: 'tenant_site_1',
|
|
135
|
+
username: 'user@tenant.com',
|
|
136
|
+
password: 'user-password',
|
|
137
|
+
augurInfoToken: 'admin-jwt-token' // JWT with augur_info admin privileges
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
if (result.success) {
|
|
141
|
+
// Ready-to-use API client for the target site
|
|
142
|
+
const userData = await result.targetSiteAPI!.joomla.users.get(result.userId!);
|
|
143
|
+
console.log('User authenticated:', result.username);
|
|
144
|
+
console.log('User data:', userData);
|
|
145
|
+
} else {
|
|
146
|
+
console.error('Authentication failed:', result.error);
|
|
147
|
+
}
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
### Option 2: Reusable Authenticator
|
|
151
|
+
|
|
152
|
+
```typescript
|
|
153
|
+
import { createCrossSiteAuthenticator } from '@simpleapps-com/augur-api';
|
|
154
|
+
|
|
155
|
+
// Create reusable authenticator
|
|
156
|
+
const crossSiteAuth = createCrossSiteAuthenticator('admin-jwt-token');
|
|
157
|
+
|
|
158
|
+
// Use for multiple sites
|
|
159
|
+
const result1 = await crossSiteAuth('tenant_site_1', 'user1@tenant.com', 'pass1');
|
|
160
|
+
const result2 = await crossSiteAuth('tenant_site_2', 'user2@tenant.com', 'pass2');
|
|
161
|
+
|
|
162
|
+
if (result1.success) {
|
|
163
|
+
const tenantData = await result1.targetSiteAPI!.joomla.content.list({ limit: 10 });
|
|
164
|
+
}
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
### Option 3: Manual Approach
|
|
168
|
+
|
|
169
|
+
```typescript
|
|
170
|
+
// Manual approach using the API client directly
|
|
171
|
+
const crossSiteAPI = new AugurAPI({
|
|
172
|
+
siteId: 'augur_info', // Special site for cross-site operations
|
|
173
|
+
bearerToken: 'admin-jwt-token', // JWT token with augur_info admin privileges
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
// Authenticate user against a different site
|
|
177
|
+
const authResult = await crossSiteAPI.joomla.users.verifyPassword({
|
|
178
|
+
username: 'user@tenant.com',
|
|
179
|
+
password: 'user-password',
|
|
180
|
+
siteId: 'tenant_site_1' // Target site for authentication
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
if (authResult.data.isVerified) {
|
|
184
|
+
// Create API instance for the target site
|
|
185
|
+
const tenantAPI = new AugurAPI({
|
|
186
|
+
siteId: 'tenant_site_1',
|
|
187
|
+
bearerToken: authResult.data.token, // Token scoped to tenant site
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
const userData = await tenantAPI.joomla.users.get(authResult.data.id);
|
|
191
|
+
}
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
### Cross-Site Auth Flow Diagram
|
|
195
|
+
|
|
196
|
+
```
|
|
197
|
+
[Your App] → [augur_info API] → [Target Site] → [User Validated] → [Target Site API Client]
|
|
198
|
+
↓ ↓ ↓ ↓ ↓
|
|
199
|
+
Admin Token → Verify User → Check Password → Return User Token → Ready for API calls
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
### Common Cross-Site Patterns
|
|
203
|
+
|
|
204
|
+
#### Multi-Tenant Dashboard
|
|
205
|
+
```typescript
|
|
206
|
+
// Authenticate users across multiple tenant sites
|
|
207
|
+
const authenticator = createCrossSiteAuthenticator(adminToken);
|
|
208
|
+
|
|
209
|
+
const tenants = ['site1', 'site2', 'site3'];
|
|
210
|
+
const userCredentials = { username: 'user@example.com', password: 'pass' };
|
|
211
|
+
|
|
212
|
+
const results = await Promise.all(
|
|
213
|
+
tenants.map(siteId =>
|
|
214
|
+
authenticator(siteId, userCredentials.username, userCredentials.password)
|
|
215
|
+
)
|
|
216
|
+
);
|
|
217
|
+
|
|
218
|
+
// Process results for each tenant
|
|
219
|
+
results.forEach((result, index) => {
|
|
220
|
+
if (result.success) {
|
|
221
|
+
console.log(`${tenants[index]}: User authenticated as ${result.username}`);
|
|
222
|
+
} else {
|
|
223
|
+
console.log(`${tenants[index]}: Authentication failed - ${result.error}`);
|
|
224
|
+
}
|
|
225
|
+
});
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
#### Site Switching
|
|
229
|
+
```typescript
|
|
230
|
+
// Allow users to switch between sites they have access to
|
|
231
|
+
async function switchUserToSite(username: string, password: string, targetSiteId: string) {
|
|
232
|
+
const result = await authenticateUserForSite({
|
|
233
|
+
targetSiteId,
|
|
234
|
+
username,
|
|
235
|
+
password,
|
|
236
|
+
augurInfoToken: process.env.AUGUR_INFO_ADMIN_TOKEN!
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
if (result.success) {
|
|
240
|
+
// Store the new site's API client
|
|
241
|
+
global.userAPI = result.targetSiteAPI;
|
|
242
|
+
global.currentSiteId = targetSiteId;
|
|
243
|
+
return { success: true, siteId: targetSiteId };
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
return { success: false, error: result.error };
|
|
247
|
+
}
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
### Cross-Site Error Handling
|
|
251
|
+
|
|
252
|
+
```typescript
|
|
253
|
+
try {
|
|
254
|
+
const result = await authenticateUserForSite({
|
|
255
|
+
targetSiteId: 'tenant-site',
|
|
256
|
+
username: 'user@tenant.com',
|
|
257
|
+
password: 'user-pass',
|
|
258
|
+
augurInfoToken: adminToken
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
if (!result.success) {
|
|
262
|
+
switch (result.error) {
|
|
263
|
+
case 'Invalid username or password':
|
|
264
|
+
// Handle wrong username/password
|
|
265
|
+
break;
|
|
266
|
+
case 'Site not found':
|
|
267
|
+
// Handle invalid target site (from API error)
|
|
268
|
+
break;
|
|
269
|
+
case 'Authentication failed':
|
|
270
|
+
// Handle general auth failures or network issues
|
|
271
|
+
break;
|
|
272
|
+
default:
|
|
273
|
+
// Handle other errors
|
|
274
|
+
break;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
} catch (error) {
|
|
278
|
+
console.error('Cross-site auth failed:', error.message);
|
|
279
|
+
}
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
### Security Considerations for Cross-Site Auth
|
|
283
|
+
|
|
284
|
+
1. **Admin Token Security**: The `augur_info` admin token is very powerful - store it extremely securely
|
|
285
|
+
2. **Audit Logging**: Log all cross-site authentication attempts for security monitoring
|
|
286
|
+
3. **Rate Limiting**: Implement rate limiting to prevent brute force attacks
|
|
287
|
+
4. **Token Scoping**: Returned tokens are scoped to the target site only
|
|
288
|
+
5. **Session Management**: Properly manage and clean up cross-site sessions
|
|
289
|
+
|
|
290
|
+
### When NOT to Use Cross-Site Auth
|
|
291
|
+
|
|
292
|
+
Don't use cross-site authentication if:
|
|
293
|
+
- You're working with a single site (use standard auth)
|
|
294
|
+
- You don't have admin-level access to `augur_info`
|
|
295
|
+
- You're building a simple application without multi-tenancy
|
|
296
|
+
- Security requirements prohibit cross-site token exchange
|
|
297
|
+
|
|
298
|
+
---
|
|
299
|
+
|
|
300
|
+
## Troubleshooting Authentication
|
|
301
|
+
|
|
302
|
+
### Common Issues
|
|
303
|
+
|
|
304
|
+
**"Authentication failed" (401 Error)**
|
|
305
|
+
- Check your `bearerToken` is correct and not expired
|
|
306
|
+
- Verify your `siteId` matches your environment
|
|
307
|
+
- For cross-site auth, ensure your admin token has `augur_info` privileges
|
|
308
|
+
|
|
309
|
+
**"Forbidden" (403 Error)**
|
|
310
|
+
- Your token is valid but doesn't have permission for this operation
|
|
311
|
+
- Check if you need admin-level permissions
|
|
312
|
+
- Verify the site ID matches the token's scope
|
|
313
|
+
|
|
314
|
+
**"Site not found" (Cross-site auth)**
|
|
315
|
+
- Verify the target site ID exists and is accessible
|
|
316
|
+
- Check that the target site is properly configured
|
|
317
|
+
- Ensure your admin token has access to the target site
|
|
318
|
+
|
|
319
|
+
**Token Expiration**
|
|
320
|
+
- Implement token refresh logic
|
|
321
|
+
- Monitor token expiration times
|
|
322
|
+
- Have fallback authentication flow
|
|
323
|
+
|
|
324
|
+
### Authentication Testing
|
|
325
|
+
|
|
326
|
+
```typescript
|
|
327
|
+
// Test standard authentication
|
|
328
|
+
async function testAuth() {
|
|
329
|
+
try {
|
|
330
|
+
const api = new AugurAPI({
|
|
331
|
+
siteId: 'your-site-id',
|
|
332
|
+
bearerToken: 'your-token'
|
|
333
|
+
});
|
|
334
|
+
|
|
335
|
+
// Simple test call
|
|
336
|
+
const health = await api.joomla.getHealthCheck();
|
|
337
|
+
console.log('✅ Authentication working:', health.data.status);
|
|
338
|
+
|
|
339
|
+
// Test authenticated call
|
|
340
|
+
const users = await api.joomla.users.list({ limit: 1 });
|
|
341
|
+
console.log('✅ Authenticated API calls working');
|
|
342
|
+
|
|
343
|
+
} catch (error) {
|
|
344
|
+
console.error('❌ Authentication failed:', error.message);
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
// Test cross-site authentication
|
|
349
|
+
async function testCrossSiteAuth() {
|
|
350
|
+
try {
|
|
351
|
+
const result = await authenticateUserForSite({
|
|
352
|
+
targetSiteId: 'test-site',
|
|
353
|
+
username: 'test-user',
|
|
354
|
+
password: 'test-pass',
|
|
355
|
+
augurInfoToken: 'admin-token'
|
|
356
|
+
});
|
|
357
|
+
|
|
358
|
+
if (result.success) {
|
|
359
|
+
console.log('✅ Cross-site auth working');
|
|
360
|
+
const testCall = await result.targetSiteAPI!.joomla.getHealthCheck();
|
|
361
|
+
console.log('✅ Target site API working:', testCall.data.status);
|
|
362
|
+
} else {
|
|
363
|
+
console.error('❌ Cross-site auth failed:', result.error);
|
|
364
|
+
}
|
|
365
|
+
} catch (error) {
|
|
366
|
+
console.error('❌ Cross-site auth error:', error.message);
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
```
|
|
370
|
+
|
|
371
|
+
For most applications, stick with standard authentication. Only implement cross-site authentication if you specifically need multi-tenant capabilities.
|