improve clerk sdk use
This commit is contained in:
+12
-15
@@ -10,7 +10,7 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def create_clerk_oauth_config() -> OAuthConfig:
|
||||
"""Create OAuth configuration for Clerk integration"""
|
||||
"""Create OAuth configuration for Clerk integration using SDK"""
|
||||
|
||||
# Get Clerk configuration from environment
|
||||
clerk_domain = os.getenv("CLERK_DOMAIN", "accounts.yargimcp.com")
|
||||
@@ -20,27 +20,24 @@ def create_clerk_oauth_config() -> OAuthConfig:
|
||||
if not clerk_publishable_key or not clerk_secret_key:
|
||||
raise ValueError("CLERK_PUBLISHABLE_KEY and CLERK_SECRET_KEY are required")
|
||||
|
||||
# Determine if custom domain or standard Clerk domain
|
||||
if '.' in clerk_domain and not clerk_domain.endswith('.accounts.dev'):
|
||||
# Custom domain like accounts.yargimcp.com
|
||||
base_url = f"https://{clerk_domain}"
|
||||
issuer = f"https://{clerk_domain}"
|
||||
else:
|
||||
# Standard Clerk subdomain
|
||||
base_url = f"https://{clerk_domain}.accounts.dev"
|
||||
issuer = f"https://{clerk_domain}.accounts.dev"
|
||||
# For Clerk with custom domains, we use our adapter endpoints
|
||||
# This allows us to handle the custom domain flow properly
|
||||
base_url = os.getenv("BASE_URL", "https://yargimcp.com")
|
||||
|
||||
config = OAuthConfig(
|
||||
client_id=clerk_publishable_key,
|
||||
client_secret=clerk_secret_key,
|
||||
authorization_endpoint=f"{base_url}/oauth/authorize",
|
||||
token_endpoint=f"{base_url}/oauth/token",
|
||||
jwks_uri=f"{base_url}/.well-known/jwks.json",
|
||||
issuer=issuer,
|
||||
# Use our adapter endpoints instead of Clerk's direct endpoints
|
||||
authorization_endpoint=f"{base_url}/authorize",
|
||||
token_endpoint=f"{base_url}/token",
|
||||
# Keep Clerk's JWKS for token validation
|
||||
jwks_uri=f"https://{clerk_domain}/.well-known/jwks.json",
|
||||
issuer=base_url, # We're the issuer for MCP tokens
|
||||
scopes=["mcp:tools:read", "mcp:tools:write", "openid", "profile", "email"]
|
||||
)
|
||||
|
||||
logger.info(f"Created Clerk OAuth config for domain: {clerk_domain}")
|
||||
logger.info(f"Created Clerk OAuth config with adapter endpoints")
|
||||
logger.info(f"Clerk domain: {clerk_domain}")
|
||||
logger.debug(f"Authorization endpoint: {config.authorization_endpoint}")
|
||||
logger.debug(f"Token endpoint: {config.token_endpoint}")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user