Use exact diagnostic endpoint approach for JWT token creation - #133
Merged
Merged
Conversation
## 🎯 Fix JWT Token Creation Using Diagnostic Approach
### Problem
The comprehensive debugging revealed that JWT token creation fails during the 'listInstallations' call with 'A JSON web token could not be decoded' error. The diagnostic endpoint shows JWT creation as successful, indicating a discrepancy in approaches.
### Root Cause
The bot API was using a more complex private key processing approach, while the diagnostic endpoint uses a simpler approach that works. The complex approach was causing JWT token creation to fail.
### Solution
- ✅ **Use diagnostic endpoint approach**: Replace complex private key processing with simple diagnostic approach
- ✅ **Simplified JWT creation**: Use exact same createAppAuth call as diagnostic endpoint
- ✅ **Consistent private key handling**: Handle escaped newlines the same way as diagnostic
- ✅ **Removed complex fallbacks**: Eliminate alternative approaches that were causing issues
### Technical Changes
#### **Simplified Private Key Processing**
```javascript
// Before: Complex private key processing with reconstruction
// After: Simple diagnostic approach
let privateKey = process.env.GITHUB_APP_PRIVATE_KEY;
if (privateKey.includes('\\n')) {
privateKey = privateKey.replace(/\\n/g, '\n');
}
```
#### **Simplified JWT Token Creation**
```javascript
// Before: Complex createAppAuth with fallbacks
// After: Simple diagnostic approach
const { createAppAuth: createAppAuthDiag } = await import('@octokit/auth-app');
const appAuth = createAppAuthDiag({
appId: process.env.GITHUB_APP_ID,
privateKey: privateKey,
});
const appToken = await appAuth({ type: 'app' });
```
#### **Removed Complex Fallbacks**
- Removed alternative private key format attempts
- Removed complex error handling that was causing issues
- Simplified to use only the working diagnostic approach
### Files Modified
- `api/github/create-content-pr.js` - Simplified JWT token creation to match diagnostic endpoint
### Impact
- 🎯 **Uses** the exact same approach as the working diagnostic endpoint
- 🔧 **Eliminates** complex private key processing that was causing failures
- 📊 **Simplifies** JWT token creation to proven working method
- 🛠️ **Removes** fallback mechanisms that were introducing errors
- ✅ **Should resolve** the 'A JSON web token could not be decoded' error
### Testing
- [x] Simplified private key processing to match diagnostic endpoint
- [x] Simplified JWT token creation to match diagnostic endpoint
- [x] Removed complex fallback mechanisms
- [x] No linting errors
### Expected Results
The bot API should now work because:
1. **Uses exact same approach** as the working diagnostic endpoint
2. **Eliminates complex processing** that was causing JWT failures
3. **Simplified JWT creation** matches proven working method
4. **Should resolve** the 'listInstallations' JWT token error
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Collaborator
Author
|
/approve |
Contributor
|
🚀 Admin-Approved and Auto-Merged! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🎯 Fix JWT Token Creation Using Diagnostic Approach
Problem
The comprehensive debugging revealed that JWT token creation fails during the 'listInstallations' call with 'A JSON web token could not be decoded' error. The diagnostic endpoint shows JWT creation as successful, indicating a discrepancy in approaches.
Root Cause
The bot API was using a more complex private key processing approach, while the diagnostic endpoint uses a simpler approach that works. The complex approach was causing JWT token creation to fail.
Solution
Technical Changes
Simplified Private Key Processing
Simplified JWT Token Creation
Removed Complex Fallbacks
Files Modified
api/github/create-content-pr.js- Simplified JWT token creation to match diagnostic endpointImpact
Testing
Expected Results
The bot API should now work because:
Next Steps