Skip to content

Commit 04f3daa

Browse files
Restructure documentation with step-based organization
- Create step-based folder structure: environment-setup/, creating-connectors/, authentication/, user-management/, frontend-implementation/, testing/ - Each step has vectorize/ and white-label/ approaches with detailed examples - Add platform-specific guides for Google Drive and Dropbox in white-label approach - Add deprecation notices to existing platform-specific folders - Update general-guide.md to reference new step-based structure - Maintain backward compatibility with legacy guides Co-Authored-By: [email protected] <[email protected]>
1 parent 6bfe2f3 commit 04f3daa

File tree

22 files changed

+3518
-9
lines changed

22 files changed

+3518
-9
lines changed

docs/authentication/README.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Authentication
2+
3+
This section covers authentication flows for different connector approaches.
4+
5+
## Approaches
6+
7+
- **[Vectorize](./vectorize/)** - Authentication using Vectorize's managed OAuth flow
8+
- **[White-Label](./white-label/)** - Authentication using your own OAuth applications
9+
10+
## Overview
11+
12+
Authentication is the process of connecting users to their cloud storage accounts and obtaining the necessary permissions to access their files.
13+
14+
### Vectorize Approach
15+
- Users are redirected to Vectorize's platform for authentication
16+
- Vectorize handles the OAuth flow and token management
17+
- Simplified implementation with consistent user experience
18+
19+
### White-Label Approach
20+
- Users authenticate directly with your OAuth application
21+
- Full control over the authentication experience
22+
- Requires implementing OAuth callback handling
23+
24+
## Quick Reference
25+
26+
### Vectorize Authentication Flow
27+
```typescript
28+
import { getOneTimeConnectorToken, PlatformOAuth } from '@vectorize-io/vectorize-connect';
29+
30+
// 1. Generate one-time token
31+
const tokenResponse = await getOneTimeConnectorToken(config, userId, connectorId);
32+
33+
// 2. Redirect to Vectorize authentication
34+
await PlatformOAuth.redirectToVectorizeConnect(
35+
tokenResponse.token,
36+
organizationId
37+
);
38+
```
39+
40+
### White-Label Authentication Flow
41+
```typescript
42+
import { PlatformOAuth } from '@vectorize-io/vectorize-connect';
43+
44+
// Start OAuth flow in popup
45+
PlatformOAuth.startOAuth({
46+
clientId: process.env.PLATFORM_CLIENT_ID!,
47+
redirectUri: `${window.location.origin}/api/oauth/callback`,
48+
onSuccess: (response) => {
49+
// Handle successful authentication
50+
},
51+
onError: (error) => {
52+
// Handle authentication error
53+
}
54+
});
55+
```
Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
# Authentication - Vectorize Approach
2+
3+
Authenticate users using Vectorize's managed OAuth flow.
4+
5+
## One-Time Token Generation
6+
7+
Create an API endpoint to generate one-time tokens securely on the server:
8+
9+
```typescript
10+
// app/api/get-one-time-connector-token/route.ts
11+
import { getOneTimeConnectorToken, VectorizeAPIConfig } from "@vectorize-io/vectorize-connect";
12+
import { NextRequest, NextResponse } from "next/server";
13+
14+
export async function GET(request: NextRequest) {
15+
try {
16+
// Get authentication details from environment variables
17+
const apiKey = process.env.VECTORIZE_API_KEY;
18+
const organizationId = process.env.VECTORIZE_ORGANIZATION_ID;
19+
20+
if (!apiKey || !organizationId) {
21+
return NextResponse.json({
22+
error: 'Missing Vectorize API configuration'
23+
}, { status: 500 });
24+
}
25+
26+
// Configure the Vectorize API client
27+
const config: VectorizeAPIConfig = {
28+
authorization: apiKey,
29+
organizationId: organizationId
30+
};
31+
32+
// Get userId and connectorId from request url
33+
const { searchParams } = new URL(request.url);
34+
const userId = searchParams.get('userId');
35+
const connectorId = searchParams.get('connectorId');
36+
37+
// Validate userId and connectorId
38+
if (!userId || !connectorId) {
39+
return NextResponse.json({
40+
error: 'Missing userId or connectorId'
41+
}, { status: 400 });
42+
}
43+
44+
// Call Vectorize API to get the token
45+
const tokenResponse = await getOneTimeConnectorToken(
46+
config,
47+
userId,
48+
connectorId
49+
);
50+
51+
// Return the token to the client
52+
return NextResponse.json(tokenResponse, { status: 200 });
53+
54+
} catch (error) {
55+
console.error('Error generating token:', error);
56+
return NextResponse.json({
57+
error: 'Failed to generate token',
58+
message: error instanceof Error ? error.message : 'Unknown error'
59+
}, { status: 500 });
60+
}
61+
}
62+
```
63+
64+
## Frontend Authentication Flow
65+
66+
```typescript
67+
import { PlatformOAuth } from '@vectorize-io/vectorize-connect';
68+
69+
const handleAuthenticate = async () => {
70+
try {
71+
// Get one-time token from API endpoint
72+
const tokenResponse = await fetch(
73+
`/api/get-one-time-connector-token?userId=${userId}&connectorId=${connectorId}`
74+
).then(response => {
75+
if (!response.ok) {
76+
throw new Error(`Failed to generate token. Status: ${response.status}`);
77+
}
78+
return response.json();
79+
});
80+
81+
// Redirect to Vectorize authentication flow
82+
await PlatformOAuth.redirectToVectorizeConnect(
83+
tokenResponse.token,
84+
organizationId
85+
);
86+
87+
} catch (error) {
88+
console.error('Authentication failed:', error);
89+
}
90+
};
91+
```
92+
93+
## Complete Component Example
94+
95+
```typescript
96+
'use client';
97+
98+
import { useState } from 'react';
99+
import { PlatformOAuth } from '@vectorize-io/vectorize-connect';
100+
101+
export default function VectorizeConnector() {
102+
const [connectorId, setConnectorId] = useState<string | null>(null);
103+
const [isLoading, setIsLoading] = useState(false);
104+
const [error, setError] = useState<string | null>(null);
105+
106+
const handleConnect = async () => {
107+
setIsLoading(true);
108+
setError(null);
109+
110+
try {
111+
// Get one-time token from API endpoint
112+
const tokenResponse = await fetch(
113+
`/api/get-one-time-connector-token?userId=user123&connectorId=${connectorId}`
114+
).then(response => {
115+
if (!response.ok) {
116+
throw new Error(`Failed to generate token. Status: ${response.status}`);
117+
}
118+
return response.json();
119+
});
120+
121+
// Redirect to Vectorize authentication flow
122+
await PlatformOAuth.redirectToVectorizeConnect(
123+
tokenResponse.token,
124+
'your-org-id'
125+
);
126+
127+
setIsLoading(false);
128+
} catch (err: any) {
129+
const errorMessage = err instanceof Error ? err.message : 'Failed to connect';
130+
setError(errorMessage);
131+
setIsLoading(false);
132+
}
133+
};
134+
135+
return (
136+
<div className="space-y-4">
137+
<h2 className="text-lg font-semibold">Platform Connection</h2>
138+
139+
{error && (
140+
<div className="p-4 bg-red-50 text-red-700 rounded-lg">
141+
{error}
142+
</div>
143+
)}
144+
145+
<button
146+
onClick={handleConnect}
147+
disabled={!connectorId || isLoading}
148+
className="bg-green-600 text-white px-4 py-2 rounded-lg"
149+
>
150+
{isLoading ? "Connecting..." : "Connect to Platform"}
151+
</button>
152+
</div>
153+
);
154+
}
155+
```
156+
157+
## Error Handling
158+
159+
```typescript
160+
try {
161+
const tokenResponse = await getOneTimeConnectorToken(config, userId, connectorId);
162+
} catch (error) {
163+
if (error.response?.status === 401) {
164+
console.error('Invalid Vectorize API token');
165+
} else if (error.response?.status === 404) {
166+
console.error('Connector or user not found');
167+
} else {
168+
console.error('Token generation failed:', error.message);
169+
}
170+
}
171+
```
172+
173+
## Next Steps
174+
175+
- [User Management](../../user-management/vectorize/)
176+
- [Frontend Implementation](../../frontend-implementation/vectorize/)

0 commit comments

Comments
 (0)