Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
fastapi-auth-toolkit
Advanced tools
A comprehensive FastAPI authentication library that provides a robust and integrated set of features for user authentication, registration, and account management. This library also supports third-party social account authentication, making it easy to integrate with popular social platforms.
The FastAPI Auth Toolkit [Beanie] provides a comprehensive authentication solution for FastAPI applications. It offers robust features for user authentication, registration, and account management, and supports integration with popular third-party social authentication platforms.
You can install the fastapi-auth-toolkit[beanie]
package using either pip
or pipenv
.
To install the package with pip
, execute:
pip install fastapi-auth-toolkit[beanie]
db.py
from motor.motor_asyncio import AsyncIOMotorClient
# Database configuration
DATABASE_URL = "mongodb://localhost:27017"
database_name = "database_name"
# Create a MongoDB client and get the database instance
database_client = AsyncIOMotorClient(
DATABASE_URL, uuidRepresentation="standard"
)
database = database_client.get_database(database_name)
db.py
from typing import List, Type
from beanie import init_beanie, Document
# Document model registry
document_models_registry: List[Type[Document]] = []
async def init_database():
try:
# Initialize Beanie with the provided document models and database
await init_beanie(
database=database,
document_models=document_models_registry
)
print("Beanie initialized successfully.")
except Exception as e:
print(f"Error initializing Beanie: {e}")
raise
main.py
from fastapi import FastAPI
from contextlib import asynccontextmanager
from fastapi_auth_toolkit import FastapiAuthToolkitConfig
from db import document_models_registry, init_database
@asynccontextmanager
async def lifespan(app: FastAPI):
"""
Asynchronous context manager to handle application lifespan events.
:param app: The FastAPI application instance.
"""
# Initialize FastAPI Auth Toolkit
FastapiAuthToolkitConfig(
app=app,
document_models=document_models_registry,
)
# Initialize beanie document
await init_database()
# Yield control back to the FastAPI app
yield
# Create your FastAPI app
app = FastAPI(lifespan=lifespan)
jwt
, session
, or cookies
session
based auth.from fastapi_auth_toolkit import FastapiAuthToolkitConfig
FastapiAuthToolkitConfig(
auth_method="session",
)
cookies
based auth.from fastapi_auth_toolkit import FastapiAuthToolkitConfig
FastapiAuthToolkitConfig(
auth_method="cookies",
)
jwt
based auth - fully customized.from datetime import timedelta
from fastapi_auth_toolkit import FastapiAuthToolkitConfig
FastapiAuthToolkitConfig(
auth_method="jwt",
jwt_settings={
"access_token_lifetime": timedelta(minutes=5), # Example JWT settings
"refresh_token_lifetime": timedelta(days=1),
"update_last_login": False,
"algorithm": "HS256",
"auth_header_types": "Bearer",
"auth_header_name": "HTTP_AUTHORIZATION",
"user_id_field": "user_id"
},
)
FAQs
A comprehensive FastAPI authentication library that provides a robust and integrated set of features for user authentication, registration, and account management. This library also supports third-party social account authentication, making it easy to integrate with popular social platforms.
We found that fastapi-auth-toolkit demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.