Code Monkey home page Code Monkey logo

litestar-users's Issues

Enhancement: Make `roles` a seperate mixin

With the merge of #23 , role based authorization is no longer a given. We should remove the roles relationship from the User mixin and make it a seperate opt-in.

Not only will this be cleaner, it will also allow for something like this wherever roles are integrated:

if not hasattr(request.user, 'roles'):
    raise ImproperlyConfiguredException("user roles are not set up")

Custom SessionAuthMiddleware in settings

Since it isn't forbidden to specify custom auth_backend_class in LitestarUsersConfig, I'd like to redefine authentication_middleware_class with a custom middleware like this:

class CustomSessionAuthMiddleware(SessionAuthMiddleware):
    async def authenticate_request(self, connection: ASGIConnection[Any, Any, Any, Any]) -> AuthenticationResult:
        # custom logic here...
        return AuthenticationResult(user=user, auth=connection.session)
        
@dataclass
class MyCustomAppJWTAuth[User](JWTCookieAuth):
    authentication_middleware_class = CustomSessionAuthMiddleware

litestar_users_config = LitestarUsersConfig(
    auth_backend_class=MyCustomAppJWTAuth,
    ...

but litestar-users is still using the default one.
I can add CustomSessionAuthMiddleware on the app layer, but thought that litestar-users itself could use it.

No such command 'users'.

from the docs it seems you can use litestar cli however:

❯ litestar users
                                                                                
 Usage: litestar [OPTIONS] COMMAND [ARGS]...                                    
                                                                                
╭─ Error ──────────────────────────────────────────────────────────────────────╮
│ No such command 'users'.                                                     │
╰──────────────────────────────────────────────────────────────────────────────╯

my pyproject:

[tool.poetry.dependencies]
python = "^3.11"
litestar-users = "^1.2.3"
aiosqlite = "^0.20.0"


[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

Enhancement: Add password reset

Add two new handlers forgot_password and reset_password - the former emits a token, the later verifies and consumes a token.

JWT token TTL in LitestarUsersConfig

It would be great to have an explicit option for JWT token TTL in LitestarUsersConfig.
As discussed, it can be the same value as for cookie expiry (for JWTCookieAuth), but since we don't have to setup a session backend config with JWTAuth, it may be better to have a separated option.

Bug: Any user can verify themselves during registration

The user will be verified if "is_verified": true is part of the JSON payload

A mechanism should be put in place to address this, with care when a user might be created programmatically outside of the REST API scope by an administrator who wishes to bypass verification case by case.

Enhancment: MFA support

Support for MFA would be another essential feature. Integration could be done with passlib as well, using its TOTP capabilities.

Enhancement: Tests and test coverage

So far we're pretty much only testing the API endpoints, and even then not for all common scenarios.
There should be unit tests for the repositories, services, guards etc.

Enhancement: Static typing

Typing is not terrible, but can definitely improve. MyPy will surely fail

Route handler typing was not updated after JWT support was added, this should be addressed.

Enhancement: Add role management interface

Currently it's only possible to create roles manually or via seeding scripts. We should add role based methods to UserService at the very least and create new route handlers at most.

Edit: The same applies to adding/revoking roles to/from users

Enhancement: Make UserService configurable

Developers will need to subclass UserService in order to write their own pre/post operation hooks for login, register, update etc. This likely requires an update to config and typing.

First doc example raises ImportError: cannot import name 'LitestarUsers' from 'litestar_users'

https://lonelyvikingmichael.github.io/litestar-users/usage/0-configuration/

I see rename LitestarUsers class to LitestarUsersPlugin so I changed it and get now:

    config=LitestarUsersConfig(
           ^^^^^^^^^^^^^^^^^^^^
  File "<string>", line 27, in __init__
  File "/home/lotso/.cache/pypoetry/virtualenvs/ollama-liteproxy-wn7kqDdW-py3.11/lib/python3.11/site-packages/litestar_users/config.py", line 279, in __post_init__
    raise ImproperlyConfiguredException(
litestar.exceptions.http_exceptions.ImproperlyConfiguredException: 500: session_backend_config must be set when auth_backend is set to "session"

other examples in the examples folder work fine oob ;) will play with that for now

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.