{"repo":"maxrdu/fastapi_login","free":true,"listed":false,"github":"https://github.com/maxrdu/fastapi_login","clone":"git clone https://github.com/maxrdu/fastapi_login.git","description":"FastAPI-Login tries to provide similar functionality as Flask-Login does.","language":"Python","stars":820,"topics":["python3","fastapi","plugin"],"license":"MIT","category":"databases-storage","readme_excerpt":"FastAPI-Login FastAPI-Login tries to provide similar functionality as Flask-Login does. Documentation In-depth documentation can be found at fastapi-login.readthedocs.io. Some examples can be found here. Installation Usage To begin we have to set up our FastAPI app: To obtain a suitable secret key you can run import secrets; print(secrets.token hex(24)) . Now we can import and setup the LoginManager , which will handle the process of encoding and decoding our Json Web Tokens. For the example we will use a dictionary to represent our user database. In your application this could also be a real database like sqlite or Postgres. It does not matter as you have to provide the function which retrieves the user. Now we have to provide the LoginManager with a way to load our user. The user loader callback should either return your user object or None Now we have to define a way to let the user login in our app. Therefore we will create a new route: Now whenever you want your user to be logged in to use a route, you can simply use your LoginManager instance as a dependency. If you also want to handle a not authenticated error, you can add your own subclass of Exception to the LoginManager. To change the expiration date of the token use the expires delta argument of the create access token method with timedelta . The default is set 15 min. Please be aware that setting a long expiry date is not considered a good practice as it would allow an attacker with the token to use your applicati","default_branch":null,"files":null,"tree":[],"storefront":"/r/maxrdu","claimed":false,"request_supported":{"post":"https://gitbuyer.com/r/maxrdu/fastapi_login/request-supported","requests":0},"note":"indexed from public GitHub; nothing is for sale on this page. Clone it from GitHub. Paid listings live at /search."}