Documentation Index
Fetch the complete documentation index at: https://mintlify.com/dvlpjrs/guMCP/llms.txt
Use this file to discover all available pages before exploring further.
Overview
The create_auth_client() factory function creates the appropriate authentication client based on the environment or a specified client type.
Source: src/auth/factory.py:12
Function Signature
from typing import Optional, TypeVar, Type
from .clients.BaseAuthClient import BaseAuthClient
T = TypeVar("T", bound=BaseAuthClient)
def create_auth_client(
client_type: Optional[Type[T]] = None,
api_key: Optional[str] = None
) -> BaseAuthClient:
Parameters
Optional specific client class to instantiate directly. If provided, this client type will be used regardless of environment.
Optional API key for Gumloop authentication. Only used when creating a GumloopAuthClient.
Returns
An instance of the appropriate BaseAuthClient implementation
Behavior
Explicit Client Type
If client_type is specified, that client is instantiated directly:
from src.auth.factory import create_auth_client
from src.auth.clients.LocalAuthClient import LocalAuthClient
# Explicitly create a local client
client = create_auth_client(client_type=LocalAuthClient)
Environment-Based Selection
If client_type is not specified, the function determines the client type from the ENVIRONMENT environment variable:
Creates a GumloopAuthClient instance with the provided api_key
Creates a LocalAuthClient instance (default behavior)
Environment Variables
Determines which auth client to create. Valid values: "gumloop", "local". Defaults to "local".
Examples
Default Usage (Environment-Based)
import os
from src.auth.factory import create_auth_client
# Set environment
os.environ["ENVIRONMENT"] = "local"
# Create appropriate client
client = create_auth_client()
# Returns LocalAuthClient instance
Gumloop Environment
import os
from src.auth.factory import create_auth_client
# Set environment
os.environ["ENVIRONMENT"] = "gumloop"
# Create Gumloop client with API key
api_key = os.environ.get("GUMLOOP_API_KEY")
client = create_auth_client(api_key=api_key)
# Returns GumloopAuthClient instance
Explicit Client Type
from src.auth.factory import create_auth_client
from src.auth.clients.GumloopAuthClient import GumloopAuthClient
# Force specific client type
client = create_auth_client(
client_type=GumloopAuthClient,
api_key="your-api-key"
)
Using the Client
from src.auth.factory import create_auth_client
# Create client
client = create_auth_client()
# Get OAuth config
config = client.get_oauth_config("slack")
# Get user credentials
creds = client.get_user_credentials("slack", "user123")
# Save credentials (if supported)
client.save_user_credentials("slack", "user123", creds)
Implementation Details
Source Code:
def create_auth_client(
client_type: Optional[Type[T]] = None, api_key: Optional[str] = None
) -> BaseAuthClient:
# If client_type is specified, use it directly
if client_type:
return client_type()
# Otherwise, determine from environment
environment = os.environ.get("ENVIRONMENT", "local").lower()
if environment == "gumloop":
from .clients.GumloopAuthClient import GumloopAuthClient
return GumloopAuthClient(api_key=api_key)
# Default to local file auth client
from .clients.LocalAuthClient import LocalAuthClient
return LocalAuthClient()
Use Cases
Development
# Local development with file-based credentials
os.environ["ENVIRONMENT"] = "local"
client = create_auth_client()
Production (Gumloop)
# Production using Gumloop infrastructure
os.environ["ENVIRONMENT"] = "gumloop"
client = create_auth_client(api_key=os.environ["GUMLOOP_API_KEY"])
Testing
# Testing with mock client
class MockAuthClient(BaseAuthClient):
def get_user_credentials(self, service_name, user_id):
return {"access_token": "mock-token"}
client = create_auth_client(client_type=MockAuthClient)
See Also