Authentication
The authenticator module provides the core authentication logic used across all supported frameworks. It handles token extraction from request headers and query parameters, token validation against the authentication service, and permission checking.
Core Components
The AuthenticateBase class is the foundation for all authentication implementations. It provides methods for extracting tokens from requests, calling the authentication service, and performing permission checks. Framework-specific implementations (FastAPI, Django, Django Ninja) extend this base class to integrate with their respective request/response patterns.
Token types supported:
- Public key:
keyquery parameter (starts withwoos-) - Private key:
private_keyquery parameter orX-Api-Keyheader - User token:
Authorization: Bearer <token>header (JWT)
The EndpointMode enum controls permission enforcement:
READ_WRITE: Allows both read and write operations (default)READ_ONLY: Restricts to GET/POST methods onlyWRITE_ONLY: Requires private keys with write permission
Type System
The types module defines data models for tokens, permissions, and project references. After successful authentication, a ProjectTokenModel is attached to the request containing:
- The validated token instance with organization/project information
- A
ProjectReferencewithorganization_idandproject_id - Context flags like
should_count(whether to count for metrics)
application_kit.authenticator.base
Framework-agnostic authentication helpers.
See also:
- FastAPI:
application_kit.fastapi.security - Django:
application_kit.django.decorators
EndpointMode
Bases: StrEnum
EndpointMode controls how an endpoint should require public or private key based on the request verb.
AuthenticateBase
AuthenticateBase(
classes=None,
token_lambda=None,
product=None,
write_permission_needed=None,
endpoint_mode=UNSET,
)
Base class that encompasses token fetching, and perform instance checks
| PARAMETER | DESCRIPTION |
|---|---|
product
|
The products required to be activated on the project.
TYPE:
|
write_permission_needed
|
Deprecated use endpoint_mode instead.
TYPE:
|
endpoint_mode
|
Controls what kind of permissions are required from the ProjectToken.
TYPE:
|
Source code in application_kit/authenticator/base.py
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 | |
get_project_token
get_project_token(
current_product,
headers,
key_token,
kind,
request_method,
port,
organization_id=None,
project_id=None,
)
Calls authentication service to get a token for an incoming request.
| PARAMETER | DESCRIPTION |
|---|---|
headers
|
The headers mapping from the request
TYPE:
|
kind
|
The kind of token detected.
TYPE:
|
organization_id
|
organization_id coming from the request path, used with user tokens.
TYPE:
|
project_id
|
project_id coming from the request path, used with user tokens.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[ProjectTokenModel, TokenModel]
|
Returns ProjectTokenModel and a TokenModel, the later will be retired. |
Source code in application_kit/authenticator/base.py
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 | |
perform_instance_checks
perform_instance_checks(
project_token, headers, request_method
)
Performs permissions, and restrictions checks, returns extra response headers.
Source code in application_kit/authenticator/base.py
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 | |
get_public_key
get_public_key(parameters, headers)
Gets a public key from request parameters.
Source code in application_kit/authenticator/base.py
215 216 217 218 219 220 221 | |
get_private_key
get_private_key(parameters, headers)
Gets a private key from either the request parameters or headers.
Source code in application_kit/authenticator/base.py
224 225 226 227 228 229 230 231 | |
get_user_access_token
get_user_access_token(parameters, headers)
Gets a user access token using the Authorization request header.
Source code in application_kit/authenticator/base.py
234 235 236 237 238 239 240 241 242 243 244 245 | |
decode_jwt
decode_jwt(jwt_token, *, allow_expired=False)
Decode and validate an access-token JWT.
allow_expired skips only the exp check (signature and every other claim are
still verified). It is used when a stale token is served in degraded mode: the auth
service issues short-lived access tokens, so a token kept for the grace window has
expired by the time it is served, yet remains the last credential we can trust.
Source code in application_kit/authenticator/base.py
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 | |
user_token_has_tombstone
user_token_has_tombstone(token_uuid)
Return True if the user token has been revoked (tombstoned) by the auth service.
Source code in application_kit/authenticator/base.py
323 324 325 326 327 328 329 330 331 | |
access_token_for_key
access_token_for_key(key, kind)
Resolve an access token, returning (token, served_stale).
Degraded mode: when the cached token is stale and the authentication service is
unavailable (transport error or 5xx, surfaced as a plain HttpException), the stale
token is served instead of failing the request and served_stale is True so the
caller can accept its expired exp. Authoritative rejections (AuthenticationFailed,
OverFreeQuota) are never softened: a stale negative-cache marker also keeps rejecting
during an outage.
Source code in application_kit/authenticator/base.py
436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 | |
authenticate_request
authenticate_request(token, kind)
Return (token, served_stale); served_stale is only ever True for key tokens.
Source code in application_kit/authenticator/base.py
461 462 463 464 465 466 467 468 469 | |
application_kit.authenticator.types
Products
Bases: StrEnum
Billable products. Each member carries its console-facing label.
Labels track the product names shown in the console (console/src/data/Products.js).
Defining the label inline (rather than in a side map) makes it intrinsic to the enum:
a new member can't be added without a label, so the two never drift. Every member has
its own distinct label — billing variants the console groups under a parent product
(the INDOOR_* kinds, the deprecated Localities fields) still get their own.
RestrictionModel
Bases: ABC, BaseModel
is_fulfilled
abstractmethod
is_fulfilled(headers)
is_fulfilled protocol method.
Source code in application_kit/authenticator/types.py
128 129 130 | |
KeyTokenInstanceModel
Bases: ABC, BaseModel
Base class for Key token instances.
check_restriction
abstractmethod
check_restriction(headers)
Checks that at least one restriction is fulfilled.
Source code in application_kit/authenticator/types.py
243 244 245 | |
check_permissions
abstractmethod
check_permissions(product, permission_names)
Checks that the instance has the permission for the product.
Source code in application_kit/authenticator/types.py
247 248 249 | |
check_write_needed
check_write_needed(method)
Checks if the method requires write permission.
Note
The following methods require write permission:
POST, PUT, DELETE and PATCH
| PARAMETER | DESCRIPTION |
|---|---|
method
|
The http method used by the request.
TYPE:
|
Source code in application_kit/authenticator/types.py
251 252 253 254 255 256 257 258 259 260 261 | |
PrivateKeyTokenInstanceModel
Bases: KeyTokenInstanceModel
Token instance for a private key.
Note
Retrived from authentication service /access_tokens/ endpoint.
check_permissions
check_permissions(product, permission_names)
Checks that the instance has the permission for the product.
Warning
This is now defunkt the only permission remaning is write for the stores product.
This is used by every products, and translates to simply "has write permission".
Source code in application_kit/authenticator/types.py
293 294 295 296 297 298 299 300 301 302 303 304 305 306 | |
check_write_needed
check_write_needed(method)
Checks if the method requires write permission.
Note
The following methods require write permission:
POST, PUT, DELETE and PATCH
| PARAMETER | DESCRIPTION |
|---|---|
method
|
The http method used by the request.
TYPE:
|
Source code in application_kit/authenticator/types.py
251 252 253 254 255 256 257 258 259 260 261 | |
PublicKeyTokenInstanceModel
Bases: KeyTokenInstanceModel
Token instance for a public key.
Note
Retrived from authentication service /access_tokens/ endpoint.
check_write_needed
check_write_needed(method)
Checks if the method requires write permission.
Note
The following methods require write permission:
POST, PUT, DELETE and PATCH
| PARAMETER | DESCRIPTION |
|---|---|
method
|
The http method used by the request.
TYPE:
|
Source code in application_kit/authenticator/types.py
251 252 253 254 255 256 257 258 259 260 261 | |
UserTokenInstanceModel
Bases: BaseModel
Token instance for a user.
Note
Retrived from the Authorization: bearer
check_staff_or_superuser
check_staff_or_superuser()
Checks if user is staff or super user. :raise PermissionDenied :return:
Source code in application_kit/authenticator/types.py
381 382 383 384 385 386 387 388 | |
check_superuser
check_superuser()
Checks if user is super user. :raise PermissionDenied
Source code in application_kit/authenticator/types.py
390 391 392 393 394 395 396 | |
check_membership
check_membership(organization_id)
Checks if user is member of the organization with organization_id.
:raise PermissionDenied
Source code in application_kit/authenticator/types.py
398 399 400 401 402 403 404 405 | |
check_ownership
check_ownership(organization_id)
Checks that user has ownership of the organization.
Source code in application_kit/authenticator/types.py
412 413 414 415 416 | |
check_origin
check_origin(headers)
Checks if the Origin is allowed for User tokens browser interactions.
Source code in application_kit/authenticator/types.py
418 419 420 421 422 423 424 425 426 427 428 429 | |
GenericCallable
Bases: Protocol
__call__
__call__(*args, **kwargs)
Generic callable takes Any as parameters and returns Any.
Source code in application_kit/authenticator/types.py
451 452 | |
ProjectReference
Bases: BaseModel
Project reference. Encapsulates the organization ID and the project ID coming from authentication.
Tip
Used to identify the targeted project by the request. For Private or Public keys tokens it's direct, but for User tokens it's a bit more involved.
User can target multiple projects or different organizations that's why the endpoints accepting
User tokens must have organization_id and project_id path arguments.
organization_id
instance-attribute
organization_id
The organization id in the authentication service.
project_id
class-attribute
instance-attribute
project_id = None
The project id in the authentication service.
trace_to_datadog
trace_to_datadog()
Add project_id, and organization_id tags to the current root span.
Source code in application_kit/authenticator/types.py
470 471 472 473 474 475 | |
ProjectTokenContext
Context object that avoids to put too much things on the request objects.
should_count
class-attribute
instance-attribute
should_count = True
If the current request should be counted.
Internal requests (eg. request Host port is 8000) are excluded from metrics counters.
source
class-attribute
instance-attribute
source = None
The source pulled from either X-SDK-Source header or if ai-context
if AI-Context header is set to true
ProjectTokenModel
ProjectTokenModel(token_instance, reference=None)
This is the main objects to interact with when using authentication.
| PARAMETER | DESCRIPTION |
|---|---|
token_instance
|
The token instance retrived from authentication service using private key
TYPE:
|
reference
|
The project reference ids.
TYPE:
|
Source code in application_kit/authenticator/types.py
504 505 506 507 508 509 510 511 512 513 | |
instance
instance-attribute
instance = token_instance
The token instance.
reference
instance-attribute
reference = reference
The project reference.
context
instance-attribute
context = ProjectTokenContext()
The current context, contains source and should_count.
products
property
products
Returns the products found in the token.
Warn
User tokens have no products.
check_product_allowed
check_product_allowed(product)
Raises ProductNotAllowed
Source code in application_kit/authenticator/types.py
526 527 528 529 530 531 | |
validate_products
validate_products(value)
Validates a product list, ignores unknown products
Source code in application_kit/authenticator/types.py
264 265 266 267 268 269 270 271 272 | |