Skip to content

Commit 8079fe6

Browse files
committed
refactor[auth]: update authentication examples to use configure_auth and add OAuth Server mode
1 parent f817416 commit 8079fe6

File tree

1 file changed

+59
-26
lines changed

1 file changed

+59
-26
lines changed

src/golf/examples/basic/auth.py

Lines changed: 59 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,42 +2,75 @@
22
33
This example shows different authentication options available in Golf 0.2.x:
44
- JWT authentication with static keys or JWKS endpoints (production)
5-
- Development authentication with static tokens (development/testing)
5+
- Static token authentication (development/testing)
6+
- OAuth Server mode (full OAuth 2.0 server)
7+
- Remote Authorization Server integration
68
"""
79

810
# Example 1: JWT authentication with a static public key
9-
# from golf.auth import configure_jwt_auth
11+
# from golf.auth import configure_auth, JWTAuthConfig
1012
#
11-
# configure_jwt_auth(
12-
# public_key_env_var="JWT_PUBLIC_KEY", # PEM-encoded public key
13-
# issuer="https://your-auth-server.com",
14-
# audience="https://your-golf-server.com",
15-
# required_scopes=["read:data"],
13+
# configure_auth(
14+
# JWTAuthConfig(
15+
# public_key_env_var="JWT_PUBLIC_KEY", # PEM-encoded public key
16+
# issuer="https://your-auth-server.com",
17+
# audience="https://your-golf-server.com",
18+
# required_scopes=["read:data"],
19+
# )
1620
# )
1721

1822
# Example 2: JWT authentication with JWKS (recommended for production)
19-
# from golf.auth import configure_jwt_auth
23+
# from golf.auth import configure_auth, JWTAuthConfig
2024
#
21-
# configure_jwt_auth(
22-
# jwks_uri_env_var="JWKS_URI", # e.g., "https://your-domain.auth0.com/.well-known/jwks.json"
23-
# issuer_env_var="JWT_ISSUER", # e.g., "https://your-domain.auth0.com/"
24-
# audience_env_var="JWT_AUDIENCE", # e.g., "https://your-api.example.com"
25-
# required_scopes=["read:user"],
25+
# configure_auth(
26+
# JWTAuthConfig(
27+
# jwks_uri_env_var="JWKS_URI", # e.g., "https://your-domain.auth0.com/.well-known/jwks.json"
28+
# issuer_env_var="JWT_ISSUER", # e.g., "https://your-domain.auth0.com/"
29+
# audience_env_var="JWT_AUDIENCE", # e.g., "https://your-api.example.com"
30+
# required_scopes=["read:user"],
31+
# )
2632
# )
2733

28-
# Example 3: Development authentication with static tokens (NOT for production)
29-
from golf.auth import configure_dev_auth
34+
# Example 3: OAuth Server mode - Golf acts as full OAuth 2.0 authorization server
35+
# from golf.auth import configure_auth, OAuthServerConfig
36+
#
37+
# configure_auth(
38+
# OAuthServerConfig(
39+
# base_url_env_var="OAUTH_BASE_URL", # e.g., "https://auth.example.com"
40+
# valid_scopes=["read", "write", "admin"], # Scopes clients can request
41+
# default_scopes=["read"], # Default scopes for new clients
42+
# required_scopes=["read"], # Scopes required for all requests
43+
# )
44+
# )
3045

31-
configure_dev_auth(
32-
tokens={
33-
"dev-token-123": {
34-
"client_id": "dev-client",
35-
"scopes": ["read", "write"],
36-
},
37-
"admin-token-456": {
38-
"client_id": "admin-client",
39-
"scopes": ["read", "write", "admin"],
46+
# Example 4: Remote Authorization Server integration
47+
# from golf.auth import configure_auth, RemoteAuthConfig, JWTAuthConfig
48+
#
49+
# configure_auth(
50+
# RemoteAuthConfig(
51+
# authorization_servers_env_var="AUTH_SERVERS", # Comma-separated: "https://auth1.com,https://auth2.com"
52+
# resource_server_url_env_var="RESOURCE_URL", # This server's URL
53+
# token_verifier_config=JWTAuthConfig(
54+
# jwks_uri_env_var="JWKS_URI"
55+
# ),
56+
# )
57+
# )
58+
59+
# Example 5: Static token authentication for development (NOT for production)
60+
from golf.auth import configure_auth, StaticTokenConfig
61+
62+
configure_auth(
63+
StaticTokenConfig(
64+
tokens={
65+
"dev-token-123": {
66+
"client_id": "dev-client",
67+
"scopes": ["read", "write"],
68+
},
69+
"admin-token-456": {
70+
"client_id": "admin-client",
71+
"scopes": ["read", "write", "admin"],
72+
},
4073
},
41-
},
42-
required_scopes=["read"],
74+
required_scopes=["read"],
75+
)
4376
)

0 commit comments

Comments
 (0)