Skip to content

Permissions

rn_forge.auth.permissions

Permission keys: the action-to-key mapping and the scope limit on tokens.

effective_permissions(permissions, *, mechanism, scopes, scope_map)

The permissions a caller may exercise, after the scope limit.

A session or basic caller keeps permissions unchanged. A bearer caller keeps only the permissions that its scopes allow through scope_map; a scope absent from the map allows nothing, and scopes never add permissions the account lacks.

Parameters:

Name Type Description Default
permissions frozenset[str]

The account's permissions.

required
mechanism Mechanism

How the caller authenticated.

required
scopes frozenset[str]

The scopes of the verified token.

required
scope_map Mapping[str, frozenset[str]]

The permissions each accepted scope allows.

required

requirement_for(permission_key, action, *, action_map=None)

The :class:Requirement for performing action on permission_key.

The action is mapped to a permission suffix and joined to the key: requirement_for("orders", "partial_update") requires orders.update.

Parameters:

Name Type Description Default
permission_key str

The resource's base permission key, such as orders.

required
action str

The action name, such as a viewset action.

required
action_map Mapping[str, str] | None

Entries that override :data:DEFAULT_PERMISSION_ACTION_MAP; actions it does not name fall back to the default map. An action named by neither map is used as the suffix unchanged.

None

Returns:

Type Description
Requirement

A requirement of all_permissions={"<permission_key>.<suffix>"}.