No project description provided
Project description
fast-sso
fastsso
is a Python package that facilitates the integration of Keycloak authentication in applications built with the FastAPI web framework.
Features 🎁
- Authentication with bearer JWT tokens.
- JWT token validation.
- Authorization based on roles, groups and the user's email verification state in Keycloak.
- Provides information about the validated user.
- Handy tools for checking roles, groups and other user attributes.
Usage 💡
Middleware
Use KeycloakFastSSOMiddleware to protect your API routes. You must first configure the connection to Keycloak with the appropriate parameters.
from fastapi import FastAPI
from keycloakfastsso.middleware import KeycloakFastSSOMiddleware
app = FastAPI()
app.add_middleware( KeycloakFastSSOMiddleware,
server_url="https://my-keycloak-url/auth/",
client_id="my-client-id",
realm_name="my-realm-name",
client_secret_key="my-client-secret-key")
Decorators
These decorators can be used to restrict access to routes based on user roles or groups.
from keycloakfastsso.decorators import require_role, require_group, require_scope, require_email_verified, require_active_user, require_token_type, require_resource_access, require_allowed_origin
@app.get("/require_role")
@require_role(["admin"])
def require_role_endpoint():
return {"Hello": "World"}
@app.get("/require_group")
@require_group(["my_group"])
def require_group_endpoint():
return {"Hello": "World"}
# other routes continue the same way
Utilities
The utilities allow you to retrieve specific information about the currently authenticated user.
from keycloakfastsso.utils import KeycloakUtils
# In your route
@app.get("/whoami")
def who_am_i(request: Request):
return {"user_id": KeycloakUtils.get_user_id(request)}
Installation 🛠️
You can install keycloakfastsso
with pip:
pip install keycloak-fast-sso
For more information on how to use this package, please refer to the official documentation.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file fastsso-1.0.1a0.tar.gz
.
File metadata
- Download URL: fastsso-1.0.1a0.tar.gz
- Upload date:
- Size: 19.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.0 CPython/3.10.12 Linux/6.2.0-36-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f822697a68829ecbd03047921c5dc7b8b136d276bd5ca5973d9e9eefe559f55b |
|
MD5 | ef10e60a19211517ff5cd52ff04dd21b |
|
BLAKE2b-256 | 85f09b9c914208e669e827bb845b6489bfd84e4fc160f37050a2c3bdb78586e3 |
File details
Details for the file fastsso-1.0.1a0-py3-none-any.whl
.
File metadata
- Download URL: fastsso-1.0.1a0-py3-none-any.whl
- Upload date:
- Size: 23.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.0 CPython/3.10.12 Linux/6.2.0-36-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f56adef154c661c7d86fe1b0ecfae039d42e11d2b1b2b72969565326de13d236 |
|
MD5 | 6205d7b92ab26f3a22e886d0f77a1f28 |
|
BLAKE2b-256 | 331c3bdcbfd549896d28a169ebb1a27848a4378d00c6562abcad54e176ac9e39 |