-
Notifications
You must be signed in to change notification settings - Fork 60
feat: add scripts for GitHub App Manifest flow #133
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
76cf387
feat: add scripts for GitHub App Manifest flow
joshjohanning 06ddb1b
refactor: rename folder
joshjohanning 7aa1583
fix: apply copilot fixes
joshjohanning 2eb5bcf
fix: check for file path
joshjohanning 8c61cef
fix: update placeholder replacement to be cross-platform compatible
joshjohanning 9cff539
fix: update usage instructions and parameter names in create-app-jwt.sh
joshjohanning File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,155 @@ | ||
| <!DOCTYPE html> | ||
| <html> | ||
| <head> | ||
| <title>GitHub App Manifest Test</title> | ||
| <style> | ||
| body { font-family: Arial, sans-serif; max-width: 800px; margin: 50px auto; padding: 20px; } | ||
| .container { background: #f6f8fa; padding: 20px; border-radius: 8px; border: 1px solid #d1d9e0; } | ||
| textarea { width: 100%; height: 300px; font-family: monospace; } | ||
| button { background: #2ea043; color: white; padding: 10px 20px; border: none; border-radius: 6px; cursor: pointer; } | ||
| button:hover { background: #2c974b; } | ||
| .warning { background: #fff3cd; border: 1px solid #ffeaa7; padding: 10px; border-radius: 4px; margin: 10px 0; } | ||
| .info { background: #d1ecf1; border: 1px solid #bee5eb; padding: 10px; border-radius: 4px; margin: 10px 0; } | ||
| .success { background: #d4edda; border: 1px solid #c3e6cb; padding: 10px; border-radius: 4px; margin: 10px 0; } | ||
| .code-block { background: #f1f3f4; border: 1px solid #d1d5da; padding: 15px; border-radius: 6px; font-family: monospace; white-space: pre-wrap; margin: 10px 0; } | ||
| .hidden { display: none; } | ||
| details { margin: 10px 0; } | ||
| summary { cursor: pointer; font-weight: bold; padding: 5px; } | ||
| .dropdown-content { padding: 10px; background: #f8f9fa; border-radius: 4px; margin-top: 5px; } | ||
| </style> | ||
| </head> | ||
| <body> | ||
| <div class="container"> | ||
| <h1>GitHub App Manifest Test</h1> | ||
|
|
||
| <div class="info"> | ||
| <strong>What happens next:</strong> | ||
| <ol> | ||
| <li>Start a local server (see instructions below)</li> | ||
| <li>Click "Create GitHub App" below</li> | ||
| <li>GitHub will redirect you to review and create the app</li> | ||
| <li>After creation, GitHub redirects back with a temporary code</li> | ||
| <li>The code will be automatically displayed and you can copy it</li> | ||
| </ol> | ||
| </div> | ||
|
|
||
| <details> | ||
| <summary>🚀 How to start local server (click to expand)</summary> | ||
| <div class="dropdown-content"> | ||
| <p>Before using this form, you need to serve this HTML file over HTTP. Run one of these commands in the directory containing this file:</p> | ||
| <div class="code-block"> | ||
| # Python 3 | ||
| python3 -m http.server 8000 | ||
|
|
||
| # Python 2 | ||
| python -m SimpleHTTPServer 8000 | ||
|
|
||
| # Node.js (if you have npx) | ||
| npx http-server -p 8000 | ||
|
|
||
| # PHP | ||
| php -S localhost:8000 | ||
| </div> | ||
| <p>Then open: <strong>http://localhost:8000/github-app-manifest-form.html</strong></p> | ||
| </div> | ||
| </details> | ||
|
|
||
| <details> | ||
| <summary>⚠️ Important Notes (click to expand)</summary> | ||
| <div class="dropdown-content"> | ||
| <div class="warning"> | ||
| <ul> | ||
| <li><strong>This will create a real GitHub App!</strong> Make sure you understand what you're doing.</li> | ||
| <li>The app will be created for organization 'joshjohanning-org'.</li> | ||
| <li>You can delete the app later from GitHub's settings if needed.</li> | ||
| <li>Make sure you're accessing this page via http://localhost:8000, not file://</li> | ||
| </ul> | ||
| </div> | ||
| </div> | ||
| </details> | ||
|
|
||
| <!-- Success message when code is received --> | ||
| <div id="success-message" class="success hidden"> | ||
| <strong>Success!</strong> Received the manifest code from GitHub: | ||
| <div class="code-block" id="manifest-code"></div> | ||
| <p>You can now use this code with the script:</p> | ||
| <div class="code-block" id="script-command"></div> | ||
| </div> | ||
|
|
||
| <form action="https://github.com/organizations/joshjohanning-org/settings/apps/new?state=abc123" method="post"> | ||
| <h3>App Manifest Configuration:</h3> | ||
| <textarea name="manifest" id="manifest" readonly></textarea> | ||
| <br><br> | ||
| <button type="submit">Create GitHub App from Manifest</button> | ||
| </form> | ||
|
|
||
| <details> | ||
| <summary>📋 How to use the manifest code (click to expand)</summary> | ||
| <div class="dropdown-content"> | ||
| <p>Once you get the code back from GitHub, you can use it with the conversion script:</p> | ||
| <div class="code-block">./create-github-app-from-manifest.sh YOUR_CODE_HERE</div> | ||
| <p>Or manually with gh CLI:</p> | ||
| <div class="code-block">gh api \ | ||
| --method POST \ | ||
| -H "Accept: application/vnd.github+json" \ | ||
| -H "X-GitHub-Api-Version: 2022-11-28" \ | ||
| /app-manifests/YOUR_CODE_HERE/conversions</div> | ||
| </div> | ||
| </details> | ||
| </div> | ||
|
|
||
| <script> | ||
| // Determine the current URL - use localhost if we're on a local server | ||
| let redirectUrl = 'http://localhost:8000/github-app-manifest-form.html'; | ||
|
|
||
| // If we're already on a proper HTTP server, use the current location | ||
| if (window.location.protocol === 'http:' || window.location.protocol === 'https:') { | ||
| redirectUrl = window.location.href.split('?')[0]; // Remove any existing query params | ||
| } | ||
|
|
||
| // Sample manifest configuration | ||
| const manifest = { | ||
| "name": "Test App from Manifest", | ||
| "url": "https://www.example.com", | ||
| "hook_attributes": { | ||
| "url": "https://example.com/github/events" | ||
| }, | ||
| "redirect_url": redirectUrl, | ||
| "callback_urls": [ | ||
| redirectUrl | ||
| ], | ||
| "public": false, | ||
| "default_permissions": { | ||
| "metadata": "read", | ||
| "contents": "read", | ||
| "issues": "write" | ||
| }, | ||
| "default_events": [ | ||
| "issues", | ||
| "issue_comment", | ||
| "push" | ||
| ] | ||
| }; | ||
|
|
||
| // Populate the textarea with the manifest JSON | ||
| document.getElementById('manifest').value = JSON.stringify(manifest, null, 2); | ||
|
|
||
| // Check if we're returning from GitHub with a code | ||
| window.addEventListener('load', function() { | ||
| const urlParams = new URLSearchParams(window.location.search); | ||
| const code = urlParams.get('code'); | ||
| const state = urlParams.get('state'); | ||
|
|
||
| if (code) { | ||
| // Show success message | ||
| document.getElementById('success-message').classList.remove('hidden'); | ||
| document.getElementById('manifest-code').textContent = code; | ||
| document.getElementById('script-command').textContent = `./create-github-app-from-manifest.sh ${code}`; | ||
|
|
||
| // Scroll to success message | ||
| document.getElementById('success-message').scrollIntoView({ behavior: 'smooth' }); | ||
| } | ||
| }); | ||
| </script> | ||
| </body> | ||
| </html> |
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
File renamed without changes.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
joshjohanning marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| set -o pipefail | ||
| client_id=$1 # Client ID as first argument | ||
joshjohanning marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
joshjohanning marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| pem=$( cat $2 ) # file path of the private key as second argument | ||
joshjohanning marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| now=$(date +%s) | ||
| iat=$((${now} - 60)) # Issues 60 seconds in the past | ||
| exp=$((${now} + 600)) # Expires 10 minutes in the future | ||
|
|
||
| b64enc() { openssl base64 | tr -d '=' | tr '/+' '_-' | tr -d '\n'; } | ||
|
|
||
| header_json='{ | ||
| "typ":"JWT", | ||
| "alg":"RS256" | ||
| }' | ||
| # Header encode | ||
| header=$( echo -n "${header_json}" | b64enc ) | ||
|
|
||
| payload_json="{ | ||
| \"iat\":${iat}, | ||
| \"exp\":${exp}, | ||
| \"iss\":\"${client_id}\" | ||
| }" | ||
| # Payload encode | ||
| payload=$( echo -n "${payload_json}" | b64enc ) | ||
|
|
||
| # Signature | ||
| header_payload="${header}"."${payload}" | ||
| signature=$( | ||
| openssl dgst -sha256 -sign <(echo -n "${pem}") \ | ||
| <(echo -n "${header_payload}") | b64enc | ||
| ) | ||
|
|
||
| # Create JWT | ||
| JWT="${header_payload}"."${signature}" | ||
| printf '%s\n' "$JWT" | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.