import json import os import sys from http.server import BaseHTTPRequestHandler, HTTPServer import jwt from common import ISSUER, PORT, kid_of, load_key KEY = load_key() JWK = json.loads(jwt.algorithms.ECAlgorithm.to_jwk(KEY.public_key())) JWK.update({"kid": kid_of(KEY), "use": "sig", "alg": "ES256"}) DOCS = { "/.well-known/openid-configuration": { "issuer": ISSUER, "jwks_uri": ISSUER + "/jwks.json", "id_token_signing_alg_values_supported": ["ES256"], "claims_supported": ["iss", "sub", "aud", "iat", "nbf", "exp", "project_id", "sandbox_id", "execution_id"], }, "/jwks.json": {"keys": [JWK]}, } class Handler(BaseHTTPRequestHandler): def do_GET(self): doc = DOCS.get(self.path) body = json.dumps(doc if doc else {"error": "not found"}).encode() self.send_response(200 if doc else 404) self.send_header("Content-Type", "application/json") self.send_header("Content-Length", str(len(body))) self.end_headers() self.wfile.write(body) def log_message(self, fmt, *args): print("issuer served", self.path, file=sys.stderr) if __name__ == "__main__": with open("issuer.pid", "w") as f: f.write(str(os.getpid())) print(f"issuer {ISSUER} kid {JWK['kid']} pid {os.getpid()}", file=sys.stderr) HTTPServer(("127.0.0.1", PORT), Handler).serve_forever()