GitHub OAuth Migration Guide
Overview
Current Issues
- ❌ PAT stored in plain text in
chrome.storage.sync (security vulnerability)
- ❌ Manual token creation/copy process (poor UX)
- ❌ Manual token expiration/renewal management
- ❌ Excessive permissions
Solution
- ✅ One-click OAuth authentication
- ✅ Access token in
chrome.storage.session (deleted on browser close)
- ✅ Automatic token refresh
- ✅ Fine-grained permission control
- ✅ Client Secret managed server-side only (Vercel)
Project Structure
Before
github-project-status-viewer/
├── src/
├── public/
├── dist/
└── package.json
After (Monorepo)
github-project-status-viewer/
├── extension/ # Chrome Extension (moved from root)
│ ├── src/
│ ├── public/
│ ├── dist/
│ └── package.json
│
├── server/ # Vercel Serverless Functions (Go)
│ ├── api/
│ │ ├── oauth-callback.go
│ │ └── refresh-token.go
│ ├── go.mod
│ └── vercel.json
│
└── README.md
Implementation Steps
1. GitHub OAuth App Setup
-
Create OAuth App at https://github.com/settings/developers
- Application name:
GitHub Project Status Viewer
- Homepage URL: Your repository URL
- Authorization callback URL:
https://<EXTENSION_ID>.chromiumapp.org/
-
Save credentials
-
Required scopes: read:project, repo
2. Restructure to Monorepo
- Move existing code to
extension/ directory
- Create
server/ directory structure
- Update build paths in
extension/justfile
3. Implement Vercel Serverless Functions (Go)
Create two API endpoints:
-
/api/oauth-callback
- Receive authorization code from extension
- Exchange code for access/refresh tokens using GitHub API
- Return tokens to extension
-
/api/refresh-token
- Receive refresh token from extension
- Request new access token from GitHub
- Return new access token
Deploy to Vercel:
- Set environment variables:
GITHUB_CLIENT_ID, GITHUB_CLIENT_SECRET
- Deploy from
server/ directory
4. Implement OAuth Flow in Extension
Update manifest.json:
Implement OAuth logic:
- Launch GitHub OAuth flow using
chrome.identity.launchWebAuthFlow
- Send authorization code to Vercel serverless function
- Store access token in
chrome.storage.session
- Store refresh token in
chrome.storage.local
Update background script:
- Replace PAT retrieval with access token from session storage
- Implement automatic token refresh when expired
Update popup UI:
- Remove PAT input field
- Add "Login with GitHub" button
- Add "Logout" button
- Display authentication status
5. Token Auto-Refresh Logic
- Check token expiration before API calls
- Automatically refresh using refresh token when expired
- Update stored access token
- Handle refresh failure (redirect to re-login)
6. Testing
- Build extension and load in Chrome
- Get Extension ID
- Update GitHub OAuth App callback URL with Extension ID
- Test OAuth login flow
- Test project status display on GitHub issues page
- Test token auto-refresh
- Test logout
7. Deployment
Vercel:
- Deploy to production
- Verify environment variables
- Test API endpoints
Chrome Extension:
- Build production version
- Upload to Chrome Web Store
- Update extension with final Extension ID
Security Checklist
Troubleshooting
- "identity API is not available" → Check
identity permission in manifest
- OAuth redirect fails → Verify callback URL matches Extension ID
- CORS error → Check CORS headers in serverless functions
- Token exchange fails → Verify Vercel environment variables
References
GitHub OAuth Migration Guide
Overview
Current Issues
chrome.storage.sync(security vulnerability)Solution
chrome.storage.session(deleted on browser close)Project Structure
Before
After (Monorepo)
Implementation Steps
1. GitHub OAuth App Setup
Create OAuth App at https://github.com/settings/developers
GitHub Project Status Viewerhttps://<EXTENSION_ID>.chromiumapp.org/Save credentials
Required scopes:
read:project,repo2. Restructure to Monorepo
extension/directoryserver/directory structureextension/justfile3. Implement Vercel Serverless Functions (Go)
Create two API endpoints:
/api/oauth-callback/api/refresh-tokenDeploy to Vercel:
GITHUB_CLIENT_ID,GITHUB_CLIENT_SECRETserver/directory4. Implement OAuth Flow in Extension
Update manifest.json:
identitypermissionImplement OAuth logic:
chrome.identity.launchWebAuthFlowchrome.storage.sessionchrome.storage.localUpdate background script:
Update popup UI:
5. Token Auto-Refresh Logic
6. Testing
7. Deployment
Vercel:
Chrome Extension:
Security Checklist
chrome.storage.sessionTroubleshooting
identitypermission in manifestReferences