masonite icon indicating copy to clipboard operation
masonite copied to clipboard

Auth.get_config_options() always return default guard options

Open ReS4 opened this issue 1 year ago • 0 comments

Describe the bug

The framework doesn't load related config options when using custom guards for authentication.

Expected behaviour

It should return the options dict instead of the default guard options.

masonite/authentication/Auth.py

...

    def get_config_options(self, guard=None):
        if guard is None:  # Because the guard is always `None`, the default config will load
            options = self.guard_config.get(self.guard_config.get("default"), {})
            options.update(self.options)
            return options

        options = self.guard_config.get(guard, {})
        options.update(self.options)
        return options
...

masonite never passes any argument as guard to get_config_options() !

Steps to reproduce the bug

config > auth.py

GUARDS = {
    "default": "web",
    "web": {"model": User},
    "admin": {"model": Admins},
    "password_reset_table": "password_resets",
    "password_reset_expiration": 1440,  # in minutes. 24 hours. None if disabled
}

CustomAdminGuard.py almost same as the WebGuard.py

AppProvider.py

...

    def register(self):
        auth = self.application.make("auth")
        ...
        auth.add_guard("admin", CustomAdminGuard(self.application))
...

MyController.py


    ...
    def store(self, request: Request, auth: Auth, response: Response, session: Session):

        if not auth.guard('admin').user(): 
            admin = auth.guard('admin').attempt(request.input("email"), request.input("password"), True)
    ...

Masonite Version

4.20.0

ReS4 avatar Nov 07 '24 20:11 ReS4