63 Commits

Author SHA1 Message Date
caa17889e1 Drop Python 3.8 support 2024-11-03 12:51:32 +00:00
abfa9a1c47 Improve type hints (#1401)
* Add type parameters to `AuthenticationBackend`

* add more type-hints
2024-07-14 15:04:13 +02:00
fe932fee19 Add request parameter to delete user method (#1258)
* add request parameter to delete_user method.

* Docs: Add request parameter to docstring
2023-07-26 13:10:03 +02:00
e17bb609ae Add compatibility layer for Pydantic V2 2023-07-12 10:44:22 +02:00
8959a12d56 Update verify.py (#1200)
* Update verify.py

When using a schema setup as proposed in the documentation like: ReadUser, CreateUser, UpdateUser and BaseUser in the combination with MongoDB / Beanie, the verify() method will not "enforce" the `user_schema` but instead will return the `BaseUser` which will cause serialisation errors as such:

```
pydantic.error_wrappers.ValidationError: 1 validation error for ReadUser
response -> id
```
because the mapping between MongoDBs internal `_id` and the Pydantic `id` does not work.

* use `from_orm`
2023-04-29 10:21:01 +02:00
a63264c99e Fix #1166: add type hint to /users/{id} routes 2023-04-27 09:41:22 +02:00
8fd097cbc8 Revamp Transport so they always build a full Response object (#1049)
* Revamp Transport so they always build a full Response object

* Fix linting

* Add private methods to set cookies on CookieTransport

* Change on_after_login login_return parameter to response
2023-04-27 09:32:49 +02:00
4e426d6823 Add login_return to on_after_login method (#1187) 2023-04-14 16:10:22 +02:00
982acb13fb Fix typings 2023-03-15 13:42:57 +01:00
9b57fa2e73 Allow to set is_verified to True after OAuth callback 2023-02-13 17:42:31 +01:00
4daa263326 Fix typing 2023-01-16 10:20:23 +01:00
c91e7657db Update for httpx-oauth >= 0.10 where account_email can be None 2022-11-04 09:35:51 +01:00
7ad5f8073d on_after_login hook (#1092)
* on_after_login minimal impl.

Questions: is the spot logical for after method? Is after the internal login call.
Would before_login be needed? Maybe not, as auth is the way to do pre-login things.

Added fastapi request as a param just in case, as other callbacks had it too.

Docs addition is missing.

* tried to complete the implementation, but the test with user_manager.on_after_login.called fails though

* move on_after_login tests to right place, to TestLogin. These ones pass.

TODO: check TestCallback

* on_after_login tests to TestCallback too, for oauth. Apparently test_redirect_url_router fires the callback too, I guess that's correct, am not using oauth myself.

* fix formatting with make format

* docs for on_after_login

Co-authored-by: Toni Alatalo <toni.alatalo@gmail.com>
2022-10-18 08:02:01 +02:00
f4338ca3df Handle UserAlreadyExists error in oauth callback route 2022-06-20 16:55:58 +02:00
ce15284fe9 Implement a router to associate an OAuth account with an authenticated user 2022-06-20 14:44:25 +02:00
64d3996415 Add flag to enable/disable email association with OAuth 2022-06-20 13:46:47 +02:00
1b6b58c0e0 Manually cast user to User schema in routes to avoid issue #1000 2022-05-25 08:27:46 +02:00
78be936297 Put exceptions in a dedicated module to avoid circular imports 2022-05-06 13:17:22 +02:00
72aa68c462 Native model and generic ID (#971)
* Use a generic Protocol model for User instead of Pydantic

* Remove UserDB Pydantic schema

* Harmonize schema variable naming to avoid confusions

* Revamp OAuth account model management

* Revamp AccessToken DB strategy to adopt generic model approach

* Make ID a generic instead of forcing UUIDs

* Improve generic typing

* Improve Strategy typing

* Tweak base DB typing

* Don't set Pydantic schemas on FastAPIUsers class: pass it directly on router creation

* Add IntegerIdMixin and export related classes

* Start to revamp doc for V10

* Revamp OAuth documentation

* Fix code highlights

* Write the 9.x.x ➡️ 10.x.x migration doc

* Fix pyproject.toml
2022-05-05 14:51:19 +02:00
04e432acad Unique names for routes (#916) 2022-02-11 08:07:45 +01:00
e6125905e0 Fix #865 (#866)
* Fix #865

* Add # pragma: no cover to all try blocks

* Fix same issue with root module
2022-01-15 10:50:06 +01:00
c4de66b81c Revamp authentication (#831)
* Implement Transport classes

* Implement authentication strategy classes

* Revamp authentication with Transport and Strategy

* Revamp strategy and OAuth so that they can use a callable dependency

* Update docstring

* Make ErrorCode a proper Enum and cleanup unused OpenAPI utils

* Remove useless check

* Tweak typing in authenticator

* Update docs

* Improve logout/destroy token logic

* Update docs

* Update docs

* Update docs and full examples

* Apply formatting to examples

* Update OAuth doc and examples

* Add migration doc

* Implement Redis session token

* Add Redis Session documentation

* RedisSession -> Redis

* Fix links in docs
2021-12-30 15:22:07 +01:00
2e8f1f2eb2 Fixed #823 (#824)
* Added a failing test for the multi-oauth-router issue

* Fixed the #823 regression.

Using a regex for the backend name validation instead of an enum.

* Fixed formatting errors

* Moved the `AuthenticationBackendName` enum to `Authenticator`

This prevents an issue with OpenAPI schema generation caused by two
endpoints accepting a parameter with a duplicate name.
2021-12-29 13:25:15 +01:00
c759bb6915 Extending generated OpenAPI docs (#799)
* Added login endpoint docs

* make format

* Changed login route into multiple examples.

* Added reset password router docs

* Updated /{id} routes for user

* Updated /me routes

* Fixed user already exists response description

* Updated the /register route

* Updated verify routes

* Updated oauth2 endpoints.

* Applied `make format`

* Renamed Authentication methods for getting their openapi schemas

- `get_login_responses_success` -> `get_openapi_login_responses_success`
- `get_logout_responses_success` -> `get_openapi_logout_responses_success`

* Fixed flake8 errors

* Not using `Final` to keep python37 compatibility

Co-authored-by: François Voron <fvoron@gmail.com>
2021-11-23 13:13:51 +01:00
48d1be87a4 Added codestyle check and lint to the build action (#798)
* Applied `make format`

* Added format-check to makefile

* Added a "Check codestyle" step to the build action.

* Rerun `make format`

* Added a "lint" target to makefile

* Added lint step to the build action

* Added W503 to the list of ignored flake8 errors.

See https://www.flake8rules.com/rules/W503.html
2021-11-23 08:13:11 +01:00
f578a01a8b Updated OAuth2 router generator for better OpenAPI docs (#793)
* Added OAuth2 authorize route response_model

* Changed OAuth2 "authorize" route backend param type.

On OAuth2 router creation, an enum is created for the `authentication_backend` parameter. This allows us to generate OpenAPI docs correctly.

* Reformatted with "make format"

* Updated OAuth2 authorize url docs

- /authorize now returns 422 instead of 400 for an invalid authentication backend
2021-11-10 07:55:40 +01:00
0c45cbc179 Add a name on every route #762 (#774)
* Names for urls added

* Tests for Login/Logout Names

* Register Name Test

* tests/test_router_reset.py

* Tests to verify url names in users router

* Test Verify Router Names

* oauth routes updated with prefix

* Test for authorize.  Didn't right test for callback as covered under other tests
2021-11-02 08:12:43 +01:00
872b85de03 Code Expression (#1) (#767)
* Replace unused `for` index with underscore

* Use `items()` to directly unpack dictionary values

* Merge duplicate blocks in conditional

* Use `any()` instead of for loop

* Format __init__.py
2021-10-16 09:29:34 +02:00
eb47dc8e75 Pass user_manager instance in get_login_response/get_logout_response 2021-09-21 08:28:25 +02:00
5cba969679 Refactor verify logic into manager 2021-09-15 14:36:04 +02:00
3bdae94869 Refactor OAuth logic into manager 2021-09-15 11:57:17 +02:00
9673e0a5fd Move on_after_update to manager 2021-09-15 09:34:28 +02:00
663b7405a7 Move forgot/reset password logic to manager 2021-09-15 09:13:11 +02:00
38d4aed817 Move on_after_register to manager 2021-09-14 15:02:17 +02:00
8967138375 Inject a user manager dep callable directly to FastAPIUsers 2021-09-14 14:39:59 +02:00
480a6bc4df Move validate_password into UserManager 2021-09-14 14:01:57 +02:00
fdc8e54253 Improve generic typing 2021-09-14 11:53:43 +02:00
dade8c263d Revamp implementation with a manager layer and db class as dependency callable 2021-09-14 11:12:34 +02:00
7ae2042500 Fix #701: factorize JWT handling and support secrets as SecretStr 2021-09-09 11:51:55 +02:00
ce69ea5b8a Apply formatting 2021-08-29 17:00:59 +02:00
a95b6c45dd Fix mypy configuration 2021-08-29 15:36:04 +02:00
89c87c97f4 return empty response with 204 (#650) 2021-07-03 20:19:48 +02:00
5267e605f4 Implement password validation mechanism (#632)
* Implement password validation mechanism

* Add invalid password reason

* Always pass user in password validator

* Add password validation documentation
2021-05-17 08:58:23 +02:00
d184d7e90c Fix #609: make behavior more consistent on request verify token
Now, it always returns 202 even if the user is already verified
2021-04-20 13:54:50 +02:00
461e84acae Fix #561: Update a user with an email already existing in DB raises an error 2021-04-20 13:49:00 +02:00
ef4a54c204 Allow lifetime_seconds to be None to get session cookies 2021-03-19 18:19:58 +01:00
8eb53f4744 Fix #515: remove calls to deprecated user callables in internal codebase 2021-03-04 17:50:19 +01:00
3146a1ffe6 Fix #475: add uuid convertor to routes so they are not catching custom routes 2021-02-06 11:16:15 +01:00
d4227ae20f Fix #335: implement after_reset_password handler 2021-01-12 11:18:34 +01:00
373157c284 Finalize user activation feature (#439)
* Add routes for user activation (#403)

* Add routes for user activation

Generate a token after creating the user in register route, passing to `activation_callback`, if `activation_callback` supplied
Create new `/activate` route that will verify the token and activate the user
Add new error codes to `fastapi_users/router/common.py`
Update documentation
Add tests

Co-authored-by: Mark Todd <markpeter.todd@hotmail.co.uk>

* Rework routes for user activation

* Separate verification logic and token generation into `/fastapi_users/router/verify.py`, with per-route callbacks for custom behaviour

* Return register router to original state

* Added `is_verified` property to user models

* Added `requires_verification` argument to `get_users_router`and `get_auth_router`

* Additional dependencies added for verification in `fastapi_users/authentication/__init__.py`

* Update tests for new behaviour

* Update `README.md` to describe a workaround for possible problems during testing, by exceeding ulimit file descriptor limit

Co-authored-by: Mark Todd <markpeter.todd@hotmail.co.uk>

* Restored docs to original state.

* All other modifications reqested added

Kebab-case on request-verify-token
SECRET now used as test string
Other minor changes

Co-authored-by: Mark Todd <markpeter.todd@hotmail.co.uk>

* Embed token in body in verify route

* Reorganize checks in verify route and add unit test

* Ignore coverage on Protocol classes

* Tweak verify_user function to take full user in parameter

* Improve unit tests structure regarding parametrized test client

* Make after_verification_request optional to be more consistent with other routers

* Tweak status codes on verify routes

* Write documentation for verification feature

* Add not released warning on verify docs

Co-authored-by: Edd Salkield <edd@salkield.uk>
Co-authored-by: Mark Todd <markpeter.todd@hotmail.co.uk>
2021-01-12 10:44:42 +01:00