gws.base.auth.manager

Authorization manager.

Source code: gws.base.auth.manager

Module Contents

class gws.base.auth.manager.Config(*args, **kwargs)

Bases: gws.Config

Authentication methods, providers, sessions and login throttling.

methods: list[gws.ext.config.authMethod] | None

Login methods available to users.

mfa: list[gws.ext.config.authMultiFactorAdapter] | None

Multi-factor authentication adapters.

providers: list[gws.ext.config.authProvider] | None

User sources that verify credentials.

session: gws.ext.config.authSessionManager | None

Session storage and life time.

throttle: Config.throttle | None

Blocking of repeated failed login attempts, disabled if not set.

class gws.base.auth.manager.Object

Bases: gws.AuthManager

Authorization manager.

add_method(method)

Add an authentication method.

Parameters:

method – The method.

add_multi_factor_adapter(adapter)

Add a multi-factor adapter.

Parameters:

adapter – The adapter.

add_provider(provider)

Add an authentication provider.

Parameters:

provider – The provider.

authenticate(method, credentials, req)

Authenticate a user with the providers that allow the method.

Parameters:
  • method – The authentication method.

  • credentials – The credentials, for example username and password.

  • req – The web request.

Returns:

The user, or None if no provider accepts the credentials.

Raises:
can_use_method(req, meth)

Check if a method may be used for a request.

A secure method can only be used on secure requests, or from the addresses listed in its allowInsecureFrom.

Parameters:
  • req – The web request.

  • method – The method.

Returns:

True if the method may be used.

configure()

Configuration hook.

Called when the node is initialized. Raising an exception here aborts the creation of the node.

create_transient_session(method, user, data=None)

Create a session that lives only for the duration of the request.

The session is not stored in the session manager.

Parameters:
  • method – The method that creates the session.

  • user – The session user.

  • data – Session data.

Returns:

A new session.

enter_middleware(req: gws.WebRequester)

Begin middleware processing.

Parameters:

req – Requester object.

Returns:

A Responder object to end the request processing, or None to continue.

exit_middleware(req: gws.WebRequester, res: gws.WebResponder)

Finish middleware processing.

Parameters:
  • req – Requester object.

  • res – Current responder object.

get_method(uid=None)

Get an authentication method by its uid.

Parameters:

uid – Method uid.

Returns:

The method, or None if not found.

get_multi_factor_adapter(uid=None)

Get a multi-factor adapter by its uid.

Parameters:

uid – Adapter uid.

Returns:

The adapter, or None if not found.

get_provider(uid)

Get an authentication provider by its uid.

Parameters:

uid – Provider uid.

Returns:

The provider, or None if not found.

get_user(user_uid)

Get a user by its global uid.

Parameters:

user_uid – Global user uid.

Returns:

The user, or None if the provider is not found or does not return the user.

is_public_object(obj, *context)

Check if the guest user can read an object.

Parameters:
  • obj – The object.

  • *context – Further objects to check, before the parents.

Returns:

True if the object is public.

serialize_user(user)

Serialize a user to a string, together with its provider uid.

Parameters:

user – The user.

Returns:

A JSON string.

unserialize_user(data)

Restore a user serialized by serialize_user.

Parameters:

ser – The serialized user.

Returns:

The user, or None if the provider is not found.