Skip to content

Auth.get_config_options() always return default guard options #837

@ReS4

Description

@ReS4

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions