We're almost there! The last step is to configure the
authx object that will wire the user manager, the authentication classes and let us generate the actual API routes.
authx object with all the elements we defined before. More precisely:
UserManager: Dependency callable getter to inject the user manager class instance. See UserManager.
auth_backends: List of authentication backends. See Authentication.
user_model: Pydantic model of a user.
UserInRegister– User model for registering.
UserInCreate– User model for creating.
UserInLogin– User model for logging in.
UserPayload– User model for payloads.
SocialInCreate– Social User model for creating.
from authx import Authentication Authentication = Authentication( debug=True, base_url="http://localhost:8000", site="http://localhost:8000", database_name="authx", callback_url="http://localhost:8000/callback", access_cookie_name="access_token", refresh_cookie_name="refresh_token", private_key="private.pem", public_key="public.pem", access_expiration=3600, refresh_expiration=86400, smtp_username=None, smtp_host=None, smtp_password=None, smtp_tls=False, display_name="authx", recaptcha_secret=None, social_creds=None, social_providers=None, )
Note: We gonna discuss what we define in
We Have also an other configuration option,
This helper class will let you generate useful routers to setup the authentication system. Each of them is optional, so you can pick only the one that you are interested in! Here are the routers provided:
- Authentication: Provides
/registerand some other useful endpoints based on Authentication Provider.
- Administration: Provides all the services that an Admin can use to manage the users. (
- Password: Provides
/setendpoints to reset the password.
- social: Provides
/social/callbackendpoints to login with social networks, relate to Social Provider.
- Search: Provides
/searchendpoint to search users.
You should check out each of them to understand how to use them.