Local login
rn_forge.auth.local
Local password and development login providers.
Both are :class:~rn_forge.auth.identity.IdentityProvider implementations
over :class:~rn_forge.auth.identity.LoginRequest and need no extra. A failed login
raises :class:~rn_forge.auth.flow.LoginFailed with code login_failed.
DevelopmentAccount(subject, email=None, name=None, groups=frozenset(), attributes=dict[str, Any]())
dataclass
A fixture account the development provider offers.
Attributes:
| Name | Type | Description |
|---|---|---|
subject |
str
|
The stable subject; also the value of the |
email |
str | None
|
Email address. |
name |
str | None
|
Display name, also the link text when set. |
groups |
frozenset[str]
|
Group names. |
attributes |
Mapping[str, Any]
|
Other mapped claims. |
DevelopmentIdentityProvider(accounts, *, debug, id='development')
Bases: IdentityProvider[LoginRequest]
Sign in as a fixture account; for local development only.
Construction fails unless debug is true. :meth:render_accounts
produces this markup, with every value HTML-escaped::
<ul data-rn-forge-dev-accounts>
<li><a href="LOGIN_URL?account=SUBJECT" data-account="SUBJECT">LABEL</a></li>
</ul>
? becomes & when LOGIN_URL already has a query string.
LABEL is the account's name, or its subject when it has none. The
identity carries issuer "development" and amr of {"dev"}.
:meth:complete reads the account form field, falling back to the
account query parameter.
Attributes:
| Name | Type | Description |
|---|---|---|
id |
The configured provider ID. |
|
kind |
ProviderKind
|
Always |
Raises:
| Type | Description |
|---|---|
DevelopmentModeRequired
|
|
begin(request, *, return_to)
Return a transaction with no redirect.
complete(request, transaction)
Sign in as the account named by the account parameter.
Raises:
| Type | Description |
|---|---|
LoginFailed
|
The parameter is missing or names no fixture account. |
logout_redirect(session, *, post_logout_redirect)
Return None; logout is local only.
render_accounts(*, login_url)
Return the account list, each link pointing at login_url.
DevelopmentModeRequired
Bases: RuntimeError
The development provider was constructed without declaring debug mode.
PasswordIdentityProvider(verifier, *, id='password')
Bases: IdentityProvider[LoginRequest]
Username and password login against an application-supplied verifier.
The login is a form, so :meth:begin returns no redirect. Rate limiting
belongs to the framework binding. The password is never logged or kept.
Attributes:
| Name | Type | Description |
|---|---|---|
id |
The configured provider ID. |
|
kind |
ProviderKind
|
Always |
begin(request, *, return_to)
Return a transaction with no redirect.
complete(request, transaction)
Verify the username and password form fields.
Returns:
| Type | Description |
|---|---|
ExternalIdentity
|
An identity with issuer |
Raises:
| Type | Description |
|---|---|
LoginFailed
|
The fields are missing, the account is unknown or the password is wrong. |
logout_redirect(session, *, post_logout_redirect)
Return None; logout is local only.
PasswordVerifier
Bases: Protocol
Checks a username and password against the application's accounts.
__call__(username, password)
Return the account's stable subject, or None when the account
is unknown or the password is wrong.
json_string_fields(body)
Return the string-valued members of a JSON object body.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
body
|
bytes | str
|
A JSON document as bytes or text. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, str]
|
String fields with names as strings, or an empty dict for invalid JSON |
dict[str, str]
|
or a document that is not an object. |