Skip to main content
The pyconfigs/user.py file allows you to define custom user attributes and configure OAuth authentication providers for your Squirrels project. This enables user-specific data filtering, access control, and integration with external authentication systems.
The user.py file is optional. If it doesn’t exist, then no custom user fields are defined and no authentication providers are configured.

File structure

The user.py file typically contains:
  1. A CustomUserFields class that extends auth.CustomUserFields to define custom user attributes
  2. Optional authentication provider functions decorated with @auth.provider
pyconfigs/user.py

CustomUserFields class

The CustomUserFields class allows you to define custom attributes that are associated with each authenticated user. These fields can be used for:
  • Filtering parameter options based on user attributes
  • Access control in data models
  • User-specific context variables
  • Customizing dataset results based on user permissions

Class definition

Your CustomUserFields class must:
  • Extend auth.CustomUserFields (imported from squirrels.auth or squirrels)
  • Be named exactly CustomUserFields
  • Have a default value for all fields
pyconfigs/user.py

Supported field types

Each custom field must be one of the following types:
  • str - String values
  • int - Integer values
  • float - Float values
  • bool - Boolean values
  • typing.Literal - Literal types (e.g., Literal["option1", "option2"])
Add | None after the type to make a field nullable.
Always set a default value for each custom field. Use None if the default is null. Failure to do so will result in a validation error.

Authentication providers

Authentication providers enable OAuth-based login for your Squirrels project. Users can authenticate using external providers like Google, Microsoft, GitHub, etc.

The AuthProviderArgs object

Provider functions receive a sqrl argument of type AuthProviderArgs that provides:

Registering a provider

Use the @auth.provider decorator to register an authentication provider:
The decorated function must:

ProviderConfigs

The ProviderConfigs class requires:
  • client_id: OAuth client ID (typically from environment variables)
  • client_secret: OAuth client secret (typically from environment variables)
  • server_url: URL of the OAuth server
  • get_user: Function that converts OAuth claims to a RegisteredUser object
  • server_metadata_path: Optional path to OAuth server metadata (defaults to /.well-known/oauth-authorization-server)
  • client_kwargs: Optional dictionary of additional OAuth client arguments

External auth notes

If you set auth_strategy: external in squirrels.yml, Squirrels uses an external OAuth authorization server instead of Squirrels-managed users and API keys. In this mode:
  • You must define exactly one authentication provider function in pyconfigs/user.py.
  • The provider must support Dynamic Client Registration (DCR).
  • Provider-issued Bearer tokens may be JWTs (validated via JWKS) or opaque tokens (validated via userinfo_endpoint, with fallback to introspection_endpoint when available).

Using custom user fields examples

In context.py

Access custom user fields to create user-specific context variables:
pyconfigs/context.py

In parameter options

Filter parameter options based on user attributes:
pyconfigs/parameters.py

In Python data models

Use custom user fields for access control and filtering:
models/federates/fed_sales.py

Best practices

  1. Store secrets in environment variables: Never hardcode OAuth client IDs and secrets. Use environment variables instead.
  2. Type casting: When accessing custom fields in context.py or data models, use cast() to get proper type hints and IDE autocomplete.