quart_auth package

Module contents

class quart_auth.Action(value)

Bases: enum.Enum

An enumeration.

DELETE = 1
PASS = 2
WRITE = 3
WRITE_PERMANENT = 4
class quart_auth.AuthManager(app: Optional[quart.app.Quart] = None)

Bases: object

after_request(response: quart.wrappers.response.Response) quart.wrappers.response.Response
after_websocket(response: Optional[quart.wrappers.response.Response]) Optional[quart.wrappers.response.Response]
init_app(app: quart.app.Quart) None
resolve_user() quart_auth.AuthUser
user_class

alias of quart_auth.AuthUser

class quart_auth.AuthUser(auth_id: Optional[str])

Bases: object

A base class for users.

Any specific user implementation used with Quart-Auth should inherit from this.

property auth_id: Optional[str]
property is_authenticated: bool
class quart_auth.TestClientMixin

Bases: object

authenticated(auth_id: str) AsyncGenerator[None, None]
exception quart_auth.Unauthorized(description: Optional[str] = None, response: Optional[Response] = None, www_authenticate: Optional[Union[WWWAuthenticate, Iterable[WWWAuthenticate]]] = None)

Bases: werkzeug.exceptions.Unauthorized

exception quart_auth.UnauthorizedBasicAuth

Bases: werkzeug.exceptions.Unauthorized

quart_auth.basic_auth_required(username_key: str = 'QUART_AUTH_BASIC_USERNAME', password_key: str = 'QUART_AUTH_BASIC_PASSWORD') Callable

A decorator to restrict route access to basic authenticated users.

This should be used to wrap a route handler (or view function) to enforce that only basic authenticated requests can access it. The basic auth username and password are configurable via the app configuration with the QUART_AUTH_BASIC_USERNAME, and QUART_AUTH_BASIC_PASSWORD keys used by default. Note that it is important that this decorator be wrapped by the route decorator and not vice, versa, as below.

@app.route('/')
@basic_auth_required()
async def index():
    ...

If the request is not authenticated a quart.exceptions.UnauthorizedBasicAuth exception will be raised.

quart_auth.login_required(func: Callable) Callable

A decorator to restrict route access to authenticated users.

This should be used to wrap a route handler (or view function) to enforce that only authenticated requests can access it. Note that it is important that this decorator be wrapped by the route decorator and not vice, versa, as below.

@app.route('/')
@login_required
async def index():
    ...

If the request is not authenticated a quart.exceptions.Unauthorized exception will be raised.

quart_auth.login_user(user: quart_auth.AuthUser, remember: bool = False) None

Use this to start a session with the authenticated user.

This will result in current_user resolving to the user.

Parameters
  • user – The user to consider authenticated and to start a session for.

  • remember – If True write consider the session permanent with a duration equal to the QUART_AUTH_DURATION configuration value.

quart_auth.logout_user() None

Use this to end the session of the current_user.

quart_auth.renew_login() None

Use this to renew the cookie (a new max age).