35 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
e17bb609ae Add compatibility layer for Pydantic V2 2023-07-12 10:44: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
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
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
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
3bdae94869 Refactor OAuth logic into manager 2021-09-15 11:57: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
a95b6c45dd Fix mypy configuration 2021-08-29 15:36:04 +02:00
ef4a54c204 Allow lifetime_seconds to be None to get session cookies 2021-03-19 18:19:58 +01:00
7cf7154e27 Fix #431: make OAuth expires_at optional in model and DB schemas 2020-12-28 08:59:27 +01:00
8adce74cd9 added samesite option for cookie authentication (#337)
* added samesite option for cookie authentication

* formatted with black and added documentation (grabbed from starlette.io documentation)
2020-09-30 07:27:25 +02:00
7721f8dcc1 Revamp authentication routes structure (#201)
* Fix #68: use makefun to generate dynamic dependencies

* Remove every Starlette imports

* Split every routers and remove event handlers

* Make users router optional

* Pass after_update handler to get_users_router

* Update documentation

* Remove test file

* Write migration doc for splitted routers
2020-05-24 10:18:01 +02:00
325882436c Fix on_after_register handler not being passed Request with OAuth 2020-01-20 12:22:02 +01:00
fff167043a Fix authorize not using arbitrary redirect url 2020-01-17 16:18:49 +01:00
88b133d41c Implement OAuth2 flow (#88)
* Move users router in sub-module

* Factorize UserRouter into EventHandlersRouter

* Implement OAuth registration/login router

* Apply isort/black

* Remove temporary pytest marker

* Fix httpx-oauth version in lock file

* Ensure ON_AFTER_REGISTER event is triggered on OAuth registration

* Add API on FastAPIUsers to generate an OAuth router

* Improve test coverage of FastAPIUsers

* Small fixes

* Write the OAuth documentation

* Fix SQL unit-tests by avoiding collisions in SQLite db files
2020-01-17 11:43:17 +01:00