Skip to content
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

Remove django-allauth-2fa, dj-rest-auth and django-user-sessions #6293

Open
wants to merge 202 commits into
base: master
Choose a base branch
from

Conversation

matmair
Copy link
Member

@matmair matmair commented Jan 19, 2024

This PR remove django-allauth-2fa and replaces it with the inline functions of django-allauth. This reduces the dependency footprint and eliminates a bunch of custom creations.
It also adapts the schema generation process to include all allauth endpoints (they do not use DRF so normal generation is not working).

Update: Most of the planned things we would be interested in are now implemented and the scope shifted a bit - it makes sense to just ripp all auth extensions out and use only allauths built-in things. We have a lot of grown auth-adjacent code that can probably be removed/rewritten.

Related Issues

TODO

  • refactor authentication forms && detection of enabled features (see 8912)
  • implement custom link target lookup for email from django-allauth
  • show user ID in MFA flow
  • implement email verification flow
  • re-implement registration flow
  • re-implement password reset flow
  • re-implement password change
  • keep auth context somewhere for the local session to refer back to
  • move now removed system status info into main status (registration, mfa, sso available)
  • switch back to browser flow for auth APIs
  • rename all new auth URLs to fix to the current schema
  • include schema for auth with central API
  • write changelog

Coverage

This relies on several upstream PRs:

Copy link

netlify bot commented Jan 19, 2024

Deploy Preview for inventree-web-pui-preview canceled.

Name Link
🔨 Latest commit a68ac05
🔍 Latest deploy log https://app.netlify.com/sites/inventree-web-pui-preview/deploys/67b8252d08dc480008e52c4d

@matmair matmair added dependency Relates to a project dependency security Relates to a security issue breaking Indicates a major update or change which breaks compatibility labels Jan 19, 2024
@matmair matmair self-assigned this Jan 19, 2024
@matmair matmair added this to the 0.14.0 milestone Jan 19, 2024
@matmair matmair modified the milestones: 0.14.0, 0.13.6, 0.15.0 Feb 12, 2024
@SchrodingersGat SchrodingersGat added the setup Relates to the InvenTree setup / installation process label Feb 12, 2025
@SchrodingersGat
Copy link
Member

SchrodingersGat commented Feb 17, 2025

Some notes:

Login Conflict

If the user is already logged in, attempting a login causes a 409 error. This is throwing a ConflictResponse within allauth as the user is already authenticated. This can cause some very hard to debug behaviour (especially for the typical user) and we should consider how best to handle this.

Ref: pennersr/django-allauth#4008

Registering TOTP Code

When you register a new code (in my case, scan QR into google authenticator) but you enter the incorrect one-time code, there is no feedback / error information supplied. The screenshot below shows this - the API returns an error but there is no UI feedback

image

Login via TOTP

If you put the wrong code into the login screen there is no error message


Note: I have pushed fixes for the missing error messages, not sure how to deal with the "already logged in" state though.

@SchrodingersGat
Copy link
Member

Basic Login

Basic login (username / password) continues to work as expected (aside from the 409 error as detailed above).

TOTP Login

After making some small tweaks (see my commits above) I now have TOTP working - seems to function as expected.

  • Create new TOTP login
  • Test failure case during TOTP creation
  • Login via TOTP
  • Test failure case during TOTP login
  • Remove TOTP from user account
  • Normal login after TOTP removed

SSO

...

@matmair
Copy link
Member Author

matmair commented Feb 17, 2025

The 409 error is only a problem if running the frontend separately from the backend (ie with the vite dev server). In the production setup, the logged-in check at the beginning of the flow will catch that.
I will add some error notification.

@matmair
Copy link
Member Author

matmair commented Feb 17, 2025

I think all the mentioned issues should be addressed now, let me know if there is anything else that needs fixing.

@wolflu05
Copy link
Contributor

I'm really sorry, I won't have time currently for any review (that's why I answer so rarely). This is really a huge step for inventree to get rid of more old templating and a modernized login flow. Thank you really much for implementing this.

@SchrodingersGat
Copy link
Member

@matmair thanks for adding that error message

I don't have a way of testing SSO for this currently - have you tested this? Against which providers?

@SchrodingersGat
Copy link
Member

Regarding the playwright tests, looks like you are hitting some 500 errors:

image

image

@matmair
Copy link
Member Author

matmair commented Feb 18, 2025

@SchrodingersGat that is a database-locked error due to us running tests in parallel; this is normally fixed by just retrying a bit

@SchrodingersGat
Copy link
Member

@SchrodingersGat that is a database-locked error due to us running tests in parallel; this is normally fixed by just retrying a bit

Would it be worth (as a separate PR) moving to a postgres setup for the playwright testing in CI? We spend a significant amount of time retrying failed tests...

@matmair
Copy link
Member Author

matmair commented Feb 20, 2025

@SchrodingersGat any idea what this segmentation fault is? No idea how I introduced that

@SchrodingersGat
Copy link
Member

SchrodingersGat commented Feb 20, 2025

@matmair working on it here - #9114

(a better fix incoming in #9118)

I think that it was introduced with the new docker image. But it only fails sometimes. I can reproduce locally, under very specific conditions.

@matmair matmair marked this pull request as draft February 21, 2025 07:00
@matmair matmair marked this pull request as ready for review February 21, 2025 07:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking Indicates a major update or change which breaks compatibility dependency Relates to a project dependency full-run Always do a full QC CI run security Relates to a security issue setup Relates to the InvenTree setup / installation process
Projects
None yet
4 participants