Skip to content

Commit 506e893

Browse files
committed
Cleanup
1 parent be72803 commit 506e893

File tree

6 files changed

+42
-115
lines changed

6 files changed

+42
-115
lines changed

docker-compose.yaml

Lines changed: 2 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -59,89 +59,11 @@ services:
5959

6060
mock-oidc:
6161
build:
62-
context: ./mock_oidc_server
62+
context: ./examples/mock_oidc_server
6363
ports:
6464
- "3000:3000"
6565
volumes:
66-
- ./mock_oidc_server:/app
67-
68-
# dex:
69-
# image: ghcr.io/dexidp/dex:v2.42.0-alpine
70-
# ports:
71-
# - "5556:5556"
72-
# volumes:
73-
# - ./examples/dex/config.yaml:/etc/dex/cfg/config.yaml
74-
# entrypoint: ["dex", "serve", "/etc/dex/cfg/config.yaml"]
75-
76-
# hydra:
77-
# image: oryd/hydra:v2.2.0
78-
# ports:
79-
# - "4444:4444"
80-
# - "4445:4445"
81-
# environment:
82-
# - DSN=memory
83-
# - URLS_SELF_ISSUER=http://localhost:4444
84-
# - URLS_CONSENT=http://localhost:3000/consent
85-
# - URLS_LOGIN=http://localhost:3000/login
86-
# - SECRETS_SYSTEM=youReallyNeedToChangeThis
87-
# - LOG_LEAK_SENSITIVE_VALUES=true
88-
# - SERVE_PUBLIC_CORS_ENABLED=true
89-
# - SERVE_PUBLIC_CORS_ALLOWED_ORIGINS=*
90-
# - SERVE_PUBLIC_CORS_ALLOWED_METHODS=POST,GET,PUT,DELETE,OPTIONS
91-
# - SERVE_PUBLIC_CORS_ALLOWED_HEADERS=Authorization,Content-Type,Accept
92-
# - SERVE_PUBLIC_CORS_EXPOSED_HEADERS=Content-Type
93-
# - SERVE_PUBLIC_CORS_DEBUG=true
94-
# - SERVE_TLS_KEY_PATH=
95-
# - SERVE_TLS_CERT_PATH=
96-
# command: serve all --dev
97-
98-
# login-consent-app:
99-
# image: oryd/hydra-login-consent-node:v2.0.3
100-
# ports:
101-
# - "3000:3000"
102-
# environment:
103-
# - HYDRA_ADMIN_URL=http://hydra:4445
104-
# - NODE_TLS_REJECT_UNAUTHORIZED=0
105-
106-
# hydra-setup:
107-
# image: curlimages/curl:8.5.0
108-
# depends_on:
109-
# - hydra
110-
# entrypoint: ["/bin/sh", "-c"]
111-
# command: |
112-
# '
113-
# until curl -s http://hydra:4445/health/ready; do
114-
# echo "Waiting for Hydra to be ready..."
115-
# sleep 1
116-
# done
117-
118-
# echo "Registering OIDC client..."
119-
# curl --verbose -X POST http://hydra:4445/admin/clients \
120-
# -H "Content-Type: application/json" \
121-
# -d @- <<EOF
122-
# {
123-
# "client_id": "stac",
124-
# "client_secret": "secret",
125-
# "grant_types": ["authorization_code", "refresh_token"],
126-
# "response_types": ["code", "id_token"],
127-
# "redirect_uris": ["http://localhost:8000/docs/oauth2-redirect"],
128-
# "scope": "openid offline",
129-
# "token_endpoint_auth_method": "client_secret_post"
130-
# } EOF
131-
# '
132-
133-
# auth0:
134-
# image: public.ecr.aws/primaassicurazioni/localauth0:0.8.2
135-
# healthcheck:
136-
# test: ["CMD", "/localauth0", "healthcheck"]
137-
# ports:
138-
# - "3000:3000"
139-
# - "3001:3001"
140-
# environment:
141-
# LOCALAUTH0_CONFIG: |
142-
# issuer = "https://prima.localauth0.com/"
143-
# [user_info]
144-
# given_name = "Locie"
66+
- ./examples/mock_oidc_server:/app
14567

14668
networks:
14769
default:

examples/dex/config.yaml

Lines changed: 0 additions & 28 deletions
This file was deleted.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
jwks.json
2+
private_key.pem
File renamed without changes.

mock_oidc_server/app.py renamed to examples/mock_oidc_server/app.py

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
# ruff: noqa
21
# type: ignore
2+
"""Mock OIDC server for demo/experimentation."""
3+
34

45
import base64
56
import hashlib
7+
import json
68
import os
79
from datetime import datetime, timedelta
10+
from pathlib import Path
811
from typing import Optional
912
from urllib.parse import urlencode
1013

@@ -29,7 +32,35 @@
2932
)
3033

3134
# Configuration
32-
ISSUER = "http://localhost:3000"
35+
CLIENT_ID = os.environ.get("CLIENT_ID", "stac")
36+
CLIENT_SECRET = os.environ.get("CLIENT_SECRET", "secret")
37+
REDIRECT_URI = os.environ.get(
38+
"REDIRECT_URI", "http://localhost:8000/docs/oauth2-redirect"
39+
)
40+
ISSUER = os.environ.get("ISSUER", "http://localhost:3000")
41+
42+
# Key paths - determine from current file location
43+
APP_DIR = Path(__file__).parent
44+
PRIVATE_KEY_PATH = APP_DIR / "private_key.pem"
45+
JWKS_PATH = APP_DIR / "jwks.json"
46+
47+
48+
def load_or_generate_keys():
49+
"""Load keys from files if they exist, otherwise generate and save them."""
50+
# If both files exist, load them
51+
if PRIVATE_KEY_PATH.exists() and JWKS_PATH.exists():
52+
private_key = PRIVATE_KEY_PATH.read_text()
53+
jwks = json.loads(JWKS_PATH.read_text())
54+
return private_key, jwks
55+
56+
# Otherwise, generate new keys
57+
private_key, jwks = generate_key_pair()
58+
59+
# Save the keys
60+
PRIVATE_KEY_PATH.write_text(private_key)
61+
JWKS_PATH.write_text(json.dumps(jwks, indent=2))
62+
63+
return private_key, jwks
3364

3465

3566
# Generate RSA key pair
@@ -73,8 +104,8 @@ def int_to_base64url(value):
73104
)
74105

75106

76-
# Generate key pair on startup
77-
PRIVATE_KEY, JWKS = generate_key_pair()
107+
# Load or generate key pair on startup
108+
PRIVATE_KEY, JWKS = load_or_generate_keys()
78109

79110
# In-memory storage
80111
authorization_codes = {}
@@ -83,9 +114,9 @@ def int_to_base64url(value):
83114

84115
# Mock client registry
85116
clients = {
86-
"stac": {
87-
"client_secret": "secret",
88-
"redirect_uris": ["http://localhost:8000/docs/oauth2-redirect"],
117+
CLIENT_ID: {
118+
"client_secret": CLIENT_SECRET,
119+
"redirect_uris": [REDIRECT_URI],
89120
"grant_types": ["authorization_code"],
90121
}
91122
}
File renamed without changes.

0 commit comments

Comments
 (0)