mirror of
https://github.com/Dvorinka/Trackeep.git
synced 2026-06-03 20:12:58 +00:00
174 lines
5.4 KiB
Markdown
174 lines
5.4 KiB
Markdown
# Trackeep GitHub Integration Implementation Complete ✅
|
|
|
|
## Architecture Overview
|
|
|
|
**Centralized OAuth Service** (`oauth.tdvorak.dev`) + **User-Hosted Trackeep** = Perfect separation of concerns
|
|
|
|
### What Was Implemented
|
|
|
|
## 🔐 OAuth Service Changes
|
|
✅ **Enhanced JWT Tokens** - Now includes GitHub access token
|
|
✅ **Repo Scope Added** - `user:email`, `read:user`, `repo`
|
|
✅ **Wildcard CORS** - Allows all domains
|
|
✅ **Dynamic Client Detection** - Auto-redirects to originating domain
|
|
|
|
## 🏠 Trackeep Backend Changes
|
|
✅ **OAuth Callback Handler** - `/api/v1/auth/oauth/callback`
|
|
✅ **Enhanced User Info** - `/api/v1/auth/me` with GitHub data
|
|
✅ **GitHub API Integration** - `/api/v1/github/repos` using real access tokens
|
|
✅ **Token Pass-through** - GitHub access token embedded in Trackeep JWT
|
|
|
|
## 🎨 Frontend Changes
|
|
✅ **Updated GitHub Connect** - Points to centralized OAuth service
|
|
✅ **Enhanced Auth Callback** - Handles Trackeep backend tokens
|
|
✅ **Real GitHub Data** - No more mock data in production
|
|
|
|
## How It Works: Complete Flow
|
|
|
|
### 1. User Clicks "Connect GitHub"
|
|
```
|
|
Trackeep Frontend → https://oauth.tdvorak.dev/auth/github?redirect_uri=https://user-trackeep.com/api/v1/auth/oauth/callback
|
|
```
|
|
|
|
### 2. OAuth Service Handles GitHub
|
|
- User authenticates with GitHub
|
|
- OAuth service gets GitHub access token
|
|
- Creates JWT with: `user_info + github_access_token`
|
|
- Redirects to Trackeep backend with token
|
|
|
|
### 3. Trackeep Backend Processes
|
|
```go
|
|
// Receives: /api/v1/auth/oauth/callback?token=OAUTH_JWT
|
|
// Parses OAuth service JWT
|
|
// Extracts GitHub access token
|
|
// Creates/updates user in local DB
|
|
// Generates Trackeep JWT with embedded GitHub token
|
|
// Redirects to frontend: /auth/callback?token=TRACKEEP_JWT
|
|
```
|
|
|
|
### 4. Frontend Stores Trackeep Token
|
|
```javascript
|
|
localStorage.setItem('token', trackeepJWT);
|
|
```
|
|
|
|
### 5. GitHub API Calls
|
|
```javascript
|
|
// Frontend calls Trackeep backend
|
|
fetch('/api/v1/github/repos', {
|
|
headers: { 'Authorization': `Bearer ${trackeepJWT}` }
|
|
});
|
|
|
|
// Trackeep backend:
|
|
// 1. Validates Trackeep JWT
|
|
// 2. Extracts GitHub access token from JWT
|
|
// 3. Calls GitHub API directly
|
|
// 4. Returns real repo data
|
|
```
|
|
|
|
## Security Model
|
|
|
|
### 🔒 Token Flow
|
|
1. **OAuth Service JWT** (short-lived, for callback only)
|
|
2. **Trackeep JWT** (7-day expiry, contains GitHub token)
|
|
3. **GitHub Access Token** (passed through, used for API calls)
|
|
|
|
### 🛡️ Security Features
|
|
- CSRF protection via state parameters
|
|
- JWT token validation
|
|
- GitHub access token never exposed to frontend
|
|
- All GitHub API calls happen on backend
|
|
|
|
## Environment Variables Needed
|
|
|
|
### OAuth Service (.env)
|
|
```bash
|
|
GITHUB_CLIENT_ID=your_github_client_id
|
|
GITHUB_CLIENT_SECRET=your_github_client_secret
|
|
GITHUB_REDIRECT_URL=https://oauth.tdvorak.dev/auth/github/callback
|
|
JWT_SECRET=jgk284kd83h83hfgje3i3j
|
|
CORS_ALLOWED_ORIGINS=*
|
|
DEFAULT_CLIENT_URL=https://tdvorak.dev
|
|
SERVICE_DOMAIN=https://oauth.tdvorak.dev
|
|
```
|
|
|
|
### Trackeep Backend (.env)
|
|
```bash
|
|
JWT_SECRET=your_trackeep_jwt_secret
|
|
OAUTH_JWT_SECRET=jgk284kd83h83hfgje3i3j # Same as OAuth service
|
|
FRONTEND_URL=https://your-trackeep-instance.com
|
|
```
|
|
|
|
## API Endpoints
|
|
|
|
### OAuth Service
|
|
- `GET /auth/github` - Initiate OAuth
|
|
- `GET /auth/github/callback` - Handle GitHub callback
|
|
- `GET /api/v1/user/me` - Get user info
|
|
|
|
### Trackeep Backend
|
|
- `GET /api/v1/auth/oauth/callback` - Handle OAuth service callback
|
|
- `GET /api/v1/auth/me` - Get current user with GitHub info
|
|
- `GET /api/v1/github/repos` - Get user's GitHub repositories
|
|
|
|
## What Trackeep Can Now Track
|
|
|
|
✅ **Real Repository Data** - Names, descriptions, languages
|
|
✅ **Repository Stats** - Stars, forks, watchers, issues
|
|
✅ **Commit History** - Via GitHub API calls
|
|
✅ **Pull Requests** - Status and activity
|
|
✅ **Branch Information** - Default branch, etc.
|
|
✅ **Activity Tracking** - Last updated timestamps
|
|
|
|
## Benefits of This Architecture
|
|
|
|
### 🎯 **Separation of Concerns**
|
|
- OAuth service = Authentication only
|
|
- Trackeep = Business logic + data tracking
|
|
- Clean boundaries and responsibilities
|
|
|
|
### 🔐 **Security**
|
|
- GitHub credentials centralized
|
|
- Access tokens never exposed to frontend
|
|
- Each instance controls its own data
|
|
|
|
### 📈 **Scalability**
|
|
- OAuth service handles authentication load
|
|
- Trackeep instances handle their own GitHub API calls
|
|
- No single point of failure for data
|
|
|
|
### 🏠 **User Privacy**
|
|
- GitHub data stays in user's Trackeep instance
|
|
- No centralized data collection
|
|
- User controls their own tracking data
|
|
|
|
## Next Steps for Full Implementation
|
|
|
|
1. **Add More GitHub Endpoints**
|
|
- `/api/v1/github/repos/:owner/:repo/commits`
|
|
- `/api/v1/github/repos/:owner/:repo/pulls`
|
|
- `/api/v1/github/repos/:owner/:repo/branches`
|
|
|
|
2. **Implement Background Sync**
|
|
- Periodic GitHub API calls
|
|
- Store data in local database
|
|
- Track changes over time
|
|
|
|
3. **Add Webhook Support**
|
|
- Real-time updates from GitHub
|
|
- Instant tracking of pushes/PRs
|
|
|
|
4. **Enhanced Frontend**
|
|
- Commit history viewer
|
|
- Pull request tracking
|
|
- Activity timeline
|
|
|
|
## Deployment Ready! 🚀
|
|
|
|
The implementation is complete and ready for deployment. Users can now:
|
|
- Connect their GitHub accounts via centralized OAuth
|
|
- Track real repository data in their Trackeep instances
|
|
- Maintain full control over their data
|
|
- Scale horizontally with multiple instances
|
|
|
|
**Architecture: OAuth Service (Authentication) + Trackeep (Tracking) = Perfect Combination!** 🎉
|