Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

on_after_failed_login and on_before_login (Feature Request) #1391

Closed
Pauldic opened this issue May 23, 2024 · 1 comment
Closed

on_after_failed_login and on_before_login (Feature Request) #1391

Pauldic opened this issue May 23, 2024 · 1 comment

Comments

@Pauldic
Copy link

Pauldic commented May 23, 2024

Thanks alot for the wonderful job done thus far. You approach is really superb. I am pretty new to FastAPI but much in love with this library.

I would love to request if these 2 events could be added to the authentication (/login).
on_after_failed_login(): in case of multiple failed attempt, I would love to keep track of this failed attempt and possibly delay/deny future attempts
on_before_login() -> bool: based on the number of previous failed login attempts I may want to decide if to allow or deny login at this moment. Am thinking this would only be called after every other conditions/parameters like the password, is_active, is_verified has been checked and ready generate the jwt/access_token, such that it would allow us raise exception/return false to deny the user login access

** Also, in situation where the admin created a new user account and forwarded the credentials to the user's email. I maybe want to force the user to change the default password. I may want to abort the login process just before the final stage and redirect the user to the change password screen before s/he can proceed

This would be cleaner for further customization

@Pauldic Pauldic changed the title on_after_failed_login and on_before_login on_after_failed_login and on_before_login (Feature Request) May 23, 2024
@hgalytoby
Copy link
Contributor

hgalytoby commented May 29, 2024

I have the same need.

I am currently inheriting and overriding methods.

It would be great to add these two events.

How about on_before_login can be before line 57?

https://github.com/fastapi-users/fastapi-users/blob/master/fastapi_users/router/auth.py#L57

on_after_failed_login can be after 59 and 64?

https://github.com/fastapi-users/fastapi-users/blob/master/fastapi_users/router/auth.py#L59

https://github.com/fastapi-users/fastapi-users/blob/master/fastapi_users/router/auth.py#L64

Or here after line 657?

https://github.com/fastapi-users/fastapi-users/blob/master/fastapi_users/manager.py#L657

@fastapi-users fastapi-users locked and limited conversation to collaborators Jul 14, 2024
@frankie567 frankie567 converted this issue into discussion #1413 Jul 14, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants