Repository navigation
Expand file tree
/
Copy pathgithub-api.bat
More file actions
378 lines (327 loc) · 11.2 KB
/
Copy pathgithub-api.bat
File metadata and controls
378 lines (327 loc) · 11.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
@echo off
setlocal enabledelayedexpansion
:: API Key Forge - GitHub
:: ======================
color 0E
cls
echo.
echo ╔═══════════════════════════════════════════════════╗
echo ║ API Key Forge - GitHub ║
echo ╠═══════════════════════════════════════════════════╣
echo ║ Create Personal Access Tokens and OAuth Apps ║
echo ╚═══════════════════════════════════════════════════╝
echo.
echo What would you like to create?
echo.
echo [1] Personal Access Token (Classic)
echo [2] Fine-grained Personal Access Token (New)
echo [3] OAuth App
echo [4] GitHub App
echo [5] Deploy Keys (for specific repo)
echo [6] Webhooks
echo.
set /p choice="Enter your choice (1-6): "
if "%choice%"=="1" goto :pat_classic
if "%choice%"=="2" goto :pat_fine
if "%choice%"=="3" goto :oauth_app
if "%choice%"=="4" goto :github_app
if "%choice%"=="5" goto :deploy_keys
if "%choice%"=="6" goto :webhooks
goto :invalid
:pat_classic
cls
echo.
echo ══════════════════════════════════════════════════════
echo Personal Access Token (Classic)
echo ══════════════════════════════════════════════════════
echo.
echo This creates a token with broad permissions.
echo.
start https://github.com/settings/tokens/new
echo STEPS TO FOLLOW:
echo ----------------
echo 1. Enter a descriptive note (e.g., "Claude Session Tracker")
echo 2. Set expiration (30/60/90 days or custom)
echo 3. Select scopes you need:
echo.
echo COMMON SCOPES:
echo ✓ repo - Full control of repositories
echo ✓ workflow - Update GitHub Actions
echo ✓ write:packages - Upload packages
echo ✓ delete_repo - Delete repositories
echo ✓ admin:org - Manage organizations
echo ✓ gist - Create gists
echo ✓ notifications - Access notifications
echo ✓ user - Update profile
echo.
echo 4. Click "Generate token"
echo 5. COPY THE TOKEN NOW! (You won't see it again)
echo.
set /p scopes="What will you use this token for? "
echo.
echo Suggested scopes for: !scopes!
:: Provide scope suggestions based on use case
echo !scopes! | findstr /i "repo code" >nul
if !errorlevel! equ 0 echo - repo, workflow
echo !scopes! | findstr /i "gist" >nul
if !errorlevel! equ 0 echo - gist
echo !scopes! | findstr /i "package" >nul
if !errorlevel! equ 0 echo - write:packages, read:packages
echo.
set /p token="Paste your token here (or press Enter to skip): "
if not "!token!"=="" (
echo.
echo Your token: !token:~0,10!...
echo.
echo Save this in your .env file as:
echo GITHUB_TOKEN=!token!
echo.
echo Or set as environment variable:
echo setx GITHUB_TOKEN "!token!"
)
goto :end
:pat_fine
cls
echo.
echo ══════════════════════════════════════════════════════
echo Fine-grained Personal Access Token (Beta)
echo ══════════════════════════════════════════════════════
echo.
echo More secure with repository-specific permissions.
echo.
start https://github.com/settings/personal-access-tokens/new
echo STEPS TO FOLLOW:
echo ----------------
echo 1. Enter token name
echo 2. Set expiration (max 1 year)
echo 3. Select repositories:
echo - All repositories
echo - Selected repositories only
echo 4. Set repository permissions:
echo - Actions: Read/Write
echo - Contents: Read/Write
echo - Issues: Read/Write
echo - Pull requests: Read/Write
echo - etc.
echo 5. Set account permissions if needed
echo 6. Generate token and copy it
echo.
echo Popular permission sets:
echo.
echo [1] Read-only access
echo [2] Code contributor
echo [3] CI/CD automation
echo [4] Full repository admin
echo.
set /p perm_set="Choose a template (1-4) or Enter for custom: "
if "%perm_set%"=="1" (
echo.
echo Set these permissions to "Read":
echo - Contents, Metadata, Pull requests, Issues
)
if "%perm_set%"=="2" (
echo.
echo Set these permissions:
echo - Contents: Write
echo - Pull requests: Write
echo - Issues: Read
echo - Metadata: Read
)
if "%perm_set%"=="3" (
echo.
echo Set these permissions:
echo - Actions: Write
echo - Contents: Write
echo - Deployments: Write
echo - Packages: Write
)
pause
goto :end
:oauth_app
cls
echo.
echo ══════════════════════════════════════════════════════
echo GitHub OAuth App Setup
echo ══════════════════════════════════════════════════════
echo.
echo Create an OAuth app for user authentication.
echo.
start https://github.com/settings/applications/new
echo STEPS TO FOLLOW:
echo ----------------
echo 1. Application name: Your app's name
echo 2. Homepage URL: Your website or GitHub repo
echo 3. Authorization callback URL:
echo - Local dev: http://localhost:3000/auth/github/callback
echo - Production: https://yourdomain.com/auth/github/callback
echo 4. Click "Register application"
echo 5. Copy Client ID and generate Client Secret
echo.
set /p app_name="What's your app name? "
set /p callback="Callback URL (or Enter for localhost:3000): "
if "%callback%"=="" set callback=http://localhost:3000/auth/github/callback
echo.
echo After creation, you'll get:
echo - Client ID: (public)
echo - Client Secret: (keep secret!)
echo.
echo Save these as:
echo GITHUB_CLIENT_ID=your_client_id
echo GITHUB_CLIENT_SECRET=your_client_secret
echo.
pause
goto :end
:github_app
cls
echo.
echo ══════════════════════════════════════════════════════
echo GitHub App Setup
echo ══════════════════════════════════════════════════════
echo.
echo GitHub Apps are the future - more secure and flexible!
echo.
start https://github.com/settings/apps/new
echo STEPS TO FOLLOW:
echo ----------------
echo 1. GitHub App name: Must be unique
echo 2. Homepage URL: Your website
echo 3. Webhook URL (optional): For events
echo 4. Permissions: Be specific!
echo 5. Where can this app be installed:
echo - Only on this account
echo - Any account
echo 6. Create GitHub App
echo 7. Generate private key
echo 8. Install on your account/org
echo.
echo Key differences from OAuth Apps:
echo - Better rate limits (5000/hour)
echo - Fine-grained permissions
echo - Can act on behalf of app, not user
echo - Webhook events
echo.
pause
goto :end
:deploy_keys
cls
echo.
echo ══════════════════════════════════════════════════════
echo Repository Deploy Keys
echo ══════════════════════════════════════════════════════
echo.
echo Add SSH keys for read/write access to specific repos.
echo.
set /p repo="Enter repository (owner/name): "
if not "!repo!"=="" (
start https://github.com/!repo!/settings/keys/new
) else (
echo Please enter a repository first!
pause
goto :deploy_keys
)
echo STEPS TO FOLLOW:
echo ----------------
echo 1. Generate SSH key pair:
echo.
echo ssh-keygen -t ed25519 -C "your_email@example.com"
echo.
echo 2. Copy public key:
echo.
echo type ~/.ssh/id_ed25519.pub | clip
echo.
echo 3. Paste in GitHub
echo 4. Check "Allow write access" if needed
echo 5. Add key
echo.
set /p gen_key="Generate SSH key now? (y/n): "
if /i "%gen_key%"=="y" (
echo.
set /p email="Enter your email: "
echo Running: ssh-keygen -t ed25519 -C "!email!" -f "%USERPROFILE%\.ssh\github_deploy"
ssh-keygen -t ed25519 -C "!email!" -f "%USERPROFILE%\.ssh\github_deploy"
echo.
echo Your public key:
type "%USERPROFILE%\.ssh\github_deploy.pub"
echo.
echo Public key copied to clipboard!
type "%USERPROFILE%\.ssh\github_deploy.pub" | clip
)
goto :end
:webhooks
cls
echo.
echo ══════════════════════════════════════════════════════
echo GitHub Webhooks Setup
echo ══════════════════════════════════════════════════════
echo.
echo Receive notifications when events happen in your repo.
echo.
set /p repo="Enter repository (owner/name): "
if not "!repo!"=="" (
start https://github.com/!repo!/settings/hooks/new
) else (
echo Please enter a repository first!
pause
goto :webhooks
)
echo STEPS TO FOLLOW:
echo ----------------
echo 1. Payload URL: Your server endpoint
echo Example: https://yourserver.com/webhooks/github
echo.
echo 2. Content type: application/json
echo.
echo 3. Secret: Generate a random secret
echo Use: python -c "import secrets; print(secrets.token_hex(20))"
echo.
echo 4. Select events:
echo - Just the push event
echo - Send me everything
echo - Let me select individual events
echo.
echo Common events:
echo - Push (code pushed)
echo - Pull request (opened/closed/merged)
echo - Issues (opened/closed)
echo - Release (published)
echo - Star (someone starred)
echo.
set /p gen_secret="Generate webhook secret? (y/n): "
if /i "%gen_secret%"=="y" (
echo.
python -c "import secrets; print('Your webhook secret:', secrets.token_hex(20))"
echo.
echo Save this as: GITHUB_WEBHOOK_SECRET
)
pause
goto :end
:invalid
echo Invalid choice. Please run the script again.
pause
exit /b 1
:end
echo.
echo ══════════════════════════════════════════════════════
echo Setup Complete!
echo ══════════════════════════════════════════════════════
echo.
echo Important reminders:
echo ✓ Keep tokens secret and secure
echo ✓ Use environment variables, not hardcoded values
echo ✓ Regenerate tokens if compromised
echo ✓ Use minimal required permissions
echo ✓ Set expiration dates when possible
echo.
set /p test_now="Test your GitHub credentials? (y/n): "
if /i "%test_now%"=="y" (
echo.
echo Testing GitHub API...
echo.
if not "!token!"=="" (
curl -H "Authorization: token !token!" https://api.github.com/user
) else (
echo Please set GITHUB_TOKEN environment variable first!
)
)
echo.
pause