nameko-keycloak
docs |
|
|---|---|
tests |
|
package |
This package is still work in progress.
Helpers to integrate Single Sign-On in nameko-based applications using Keycloak.
Features
nameko service mixin
database and model-agnostic user management
authentication service
fake Keycloak client for use in tests
Installation
pip install nameko-keycloak
You can also install the in-development version with:
pip install https://github.com/emplocity/nameko-keycloak/archive/master.zip
Usage
To set up SSO with Keycloak in your nameko service, follow these steps.
Get Keycloak configuration from realm -> Clients -> Installation, download as Keycloak OIDC JSON.
Save this configuration in a .json file.
Add the mixin and dependency provider to your service and point to OIDC JSON config:
from nameko_keycloak.dependencies import KeycloakProvider from nameko_keycloak.service import KeycloakSsoServiceMixin class MyService(KeycloakSsoServiceMixin): keycloak = KeycloakProvider("/tmp/keycloak.json")Set up URLs for HTTP endpoints. The mixin exposes five methods prefixed with keycloak_, which you should use in your HTTP service. Delegate from your entrypoints like this:
@http("GET", "/login") def login_sso(self, request): return self.keycloak_login_sso(request)This way it is up to you to control the URL routes and any middleware or extra request handling (such as CORS headers).
Implement a fetch_user() method on your service that takes user’s email address as a single argument and returns a user instance for that email (or None if no such user exists in whatever storage you’re using).
For example:
def fetch_user(self, email: str) -> Optional[User]: user_manager = UserManager(self.db.session) return user_manager.get_by_email(email)This method is used to ensure that there is a local application user who matches the global identity stored in Keycloak.
(Optionally) Implement success and failure hook methods on your service.
If you provide keycloak_success() method, the mixin will call it after successful login and redirect from Keycloak back to your application. The method will receive currently logged user as its argument. Similarly the mixin will call keycloak_failure() upon Keycloak errors.
Example:
def keycloak_success(self, user: User) -> None: logger.info(f"Successful login: {user=}") def keycloak_failure(self) -> None: logger.error("Failed to log in")
Documentation
License
This work is released under the Apache 2.0 license.
Metadata
Release files for nameko-keycloak 2.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| nameko_keycloak-2.2.0.tar.gz | 11.4 kB | Without provenance | Details for nameko_keycloak-2.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| nameko_keycloak-2.2.0-py3-none-any.whl | Python 3 | none | any | Details for nameko_keycloak-2.2.0-py3-none-any.whl |
Total release size: 25.0 kB
Release files / nameko_keycloak-2.2.0.tar.gz
| Download URL | nameko_keycloak-2.2.0.tar.gz |
|---|---|
| Size | 11.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
48f1dd4b87ac378a16aa3d2b56cc4b20b2bb765980432382485aef448e719b96
|
|
BLAKE2b-256 checksum How to use checksums |
eeb3a3942730f528aabb27a4b137cc7a8e390feca839850651734f48721e31af
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.9.3
|
Release files / nameko_keycloak-2.2.0-py3-none-any.whl
| Download URL | nameko_keycloak-2.2.0-py3-none-any.whl |
|---|---|
| Size | 13.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7d526d0618c4b41dbd7a4a3b6189ba8a39e57a59832c889508e93dc41b45fc6b
|
|
BLAKE2b-256 checksum How to use checksums |
a0ff3785f355b098c0e6824299e4830722ced2e4723bc8351eb465451e08903b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.9.3
|
Security for nameko-keycloak 2.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.