Use this file to discover Exa products, pricing, evaluations, comparisons, use cases, agent interfaces, and technical documentation before exploring further.
Python authentication libraries verify who a user is through passwords, sessions, tokens, or sign-in with an outside identity provider. A web framework extension stores the signed-in user in a session cookie or a signed token. These libraries let web apps and APIs sign users in without writing password and token handling from scratch.
Popularity
Authlib has the most monthly downloads in this comparison, at 137.9M.
from authlib.integrations.requests_client import OAuth2Session
with OAuth2Session("example-client-id", "example-client-secret", scope="user:email") as client:
uri, state = client.create_authorization_url("https://github.com/login/oauth/authorize")
print(uri)
@csrf_exempt
def saml_sp_metadata(request: HttpRequest) -> HttpResponse: # nocoverage
"""
This is the view function for generating our SP metadata
for SAML authentication. It's meant for helping check the correctness
of the configuration when setting up SAML, or for obtaining the XML metadata
if the IdP requires it.
Taken from https://python-social-auth.readthedocs.io/en/latest/backends/saml.html
"""
if not saml_auth_enabled():
return config_error(request, "saml")
complete_url = reverse("social:complete", args=("saml",))
saml_backend = load_backend(load_strategy(request), "saml", complete_url)
metadata, errors = saml_backend.generate_metadata_xml()
if not errors:
return HttpResponse(content=metadata, content_type="text/xml")
return HttpResponseServerError(content=", ".join(errors))
django-otp
Adds two-factor authentication with one-time passwords to Django.
def done(self, form_list, **kwargs):
"""
Finish the wizard. Save all forms and redirect.
"""
# Remove secret key used for QR code generation try:
del self.request.session[self.session_key_name]
except KeyError:
pass
method = self.get_method()
# TOTPDeviceForm if method.code == 'generator':
form = [form for form in form_list if isinstance(form, TOTPDeviceForm)][0]
device = form.save()
# PhoneNumberForm / YubiKeyDeviceForm / EmailForm / WebauthnDeviceValidationForm elif method.code in ('call', 'sms', 'yubikey', 'email', 'webauthn'):
device = self.get_device()
device.confirmed = True
device.save()
django_otp.login(self.request, device)
return redirect(self.get_success_url())
from flask import Flask
from flask_jwt_extended import JWTManager, create_access_token
app = Flask(__name__)
app.config["JWT_SECRET_KEY"] = "super-secret" # Local example only; replace this key.
JWTManager(app)
with app.app_context():
token = create_access_token(identity="example")
print(token)
@expose("/refresh", methods=["POST"])
@jwt_required(refresh=True)
@safe
def refresh(self) -> Response:
"""
Security endpoint for the refresh token, so we can obtain a new
token without forcing the user to login again
--- post:
description: >-
Use the refresh token to get a new JWT access token
responses:
200:
description: Refresh Successful
content:
application/json:
schema:
type: object
properties:
access_token:
description: A new refreshed access token
type: string
401:
$ref: '#/components/responses/401'
500:
$ref: '#/components/responses/500'
security:
- jwt_refresh: []
"""
resp = {
API_SECURITY_ACCESS_TOKEN_KEY: create_access_token(
identity=get_jwt_identity(), fresh=False
)
}
return self.response(200, **resp)
FAQ
Flask-Login suits Flask apps that manage their own user sessions. django-allauth suits Django sites that need registration and social sign-in. Authlib suits apps that act as OAuth or OpenID Connect clients or servers.
django-allauth provides account registration, email verification, and social sign-in for Django in one package.
Flask-Login manages the signed-in user's session and protects views that require login. Token-based APIs use Flask-JWT-Extended instead.
Authlib integrates with Starlette and FastAPI for OAuth and OpenID Connect sign-in. API routes check tokens through FastAPI security dependencies.
Authlib builds OAuth and OpenID Connect clients and servers in Python. It integrates with Flask, Django, Starlette, and the requests and HTTPX clients.
For coding agents
Found your authentication library? Help your agent use it.
Connect Exa so your coding agent can find the library’s documentation, check its API, and look up implementations while you build.
Quickstart
From django.rst