Authentication

sqladmin.authentication.AuthenticationBackend 基类:AuthenticationBackend

用于在 SQLAdmin 中实现身份验证。你需要继承此类并重写以下方法:loginlogoutauthenticate

方法:

  • __init__(secret_key) 构造函数,接受 secret_key 参数。

  • authenticate(request) async 在此处实现身份验证逻辑。该方法会在每个传入请求时被调用,以验证用户的身份。 如果返回的是 ResponseRedirectResponse,该响应将返回给用户;否则,方法应返回 TrueFalse

  • login(request) async 在此处实现登录逻辑。你可以通过 await request.form() 访问登录表单数据并验证用户凭证。

  • logout(request) async 在此处实现注销逻辑。通常这将清除会话数据,执行 request.session.clear()

最后更新于