Buckets:
AnonymousSpottedToad/candidate_bucket / codebase /python /SHAdd0WTAka_Zen-Ai-Pentest /generate_installation_token.py
| #!/usr/bin/env python3 | |
| """ | |
| Generate GitHub App Installation Access Token. | |
| Uses Private Key to authenticate as the GitHub App. | |
| """ | |
| import os | |
| import sys | |
| import time | |
| from pathlib import Path | |
| import jwt | |
| # GitHub App Configuration - use env vars or defaults | |
| APP_ID = os.environ.get("GITHUB_APP_ID", "2872904") | |
| PRIVATE_KEY_PATH = Path( | |
| os.environ.get( | |
| "GITHUB_APP_PRIVATE_KEY_PATH", | |
| str(Path.home() / "Downloads" / "zen-ai-pentest-kimi-assistant.2026-02-23.private-key.pem"), | |
| ) | |
| ) | |
| def generate_jwt(): | |
| """Generate JWT from App ID and Private Key.""" | |
| with open(PRIVATE_KEY_PATH, "r") as f: | |
| private_key = f.read() | |
| payload = { | |
| "iat": int(time.time()), | |
| "exp": int(time.time()) + (10 * 60), # 10 minutes expiry | |
| "iss": APP_ID, | |
| } | |
| token = jwt.encode(payload, private_key, algorithm="RS256") | |
| return token | |
| def get_installation_token(jwt_token): | |
| """Exchange JWT for Installation Access Token.""" | |
| import json | |
| from urllib.parse import urlparse | |
| import requests | |
| url = "https://api.github.com/app/installations" | |
| if urlparse(url).scheme != "https": | |
| raise ValueError(f"Only HTTPS URLs allowed: {url}") | |
| resp = requests.get( | |
| url, | |
| headers={ | |
| "Authorization": f"Bearer {jwt_token}", | |
| "Accept": "application/vnd.github.v3+json", | |
| }, | |
| timeout=30, | |
| ) | |
| resp.raise_for_status() | |
| installations = resp.json() | |
| if not installations: | |
| return None | |
| installation_id = installations[0]["id"] | |
| url = f"https://api.github.com/app/installations/{installation_id}/access_tokens" | |
| if urlparse(url).scheme != "https": | |
| raise ValueError(f"Only HTTPS URLs allowed: {url}") | |
| resp = requests.post( | |
| url, | |
| headers={ | |
| "Authorization": f"Bearer {jwt_token}", | |
| "Accept": "application/vnd.github.v3+json", | |
| }, | |
| timeout=30, | |
| ) | |
| resp.raise_for_status() | |
| data = resp.json() | |
| return data.get("token") | |
| def main(): | |
| """Generate and display GitHub App token.""" | |
| print("๐ Generating GitHub App Installation Token...") | |
| print(f" App ID: {APP_ID}") | |
| print(f" Private Key: {PRIVATE_KEY_PATH}") | |
| if not PRIVATE_KEY_PATH.exists(): | |
| print(f"โ Private key not found at {PRIVATE_KEY_PATH}") | |
| print(" Bitte passe PRIVATE_KEY_PATH im Script an!") | |
| sys.exit(1) | |
| try: | |
| jwt_token = generate_jwt() | |
| print("โ JWT generated successfully") | |
| token = get_installation_token(jwt_token) | |
| print("\n" + "=" * 60) | |
| print("๐ INSTALLATION ACCESS TOKEN:") | |
| print("=" * 60) | |
| print(token) | |
| print("=" * 60) | |
| print("\n๐ Verwendung:") | |
| print(f" export GITHUB_TOKEN='{token}'") | |
| print(" git push https://$GITHUB_TOKEN@") | |
| print("github.com/SHAdd0WTAka/obsidian-vault.git") | |
| except Exception as e: | |
| print(f"โ Error: {e}") | |
| sys.exit(1) | |
| if __name__ == "__main__": | |
| main() | |
Xet Storage Details
- Size:
- 3.03 kB
- Xet hash:
- 4ee4c6901111e480b0a011c67c4dad686e7c7a6c5f886ac2d1f6b7359fe4c867
ยท
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.