keycloak-fast-sso


Namekeycloak-fast-sso JSON
Version 2023.11.13 PyPI version JSON
download
home_pagehttps://github.com/alexandre-meline/keycloakfastsso
SummaryFastAPI Keycloak SSO
upload_time2023-11-06 00:43:17
maintainer
docs_urlNone
authorAlexandre Meline
requires_python>=3.6
licenseMIT
keywords keycloak fastapi sso
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            .. figure:: /docs/keycloakfastsso.png
   :alt: keycloakfastsso

   keycloakfastsso

.. figure:: https://img.shields.io/pypi/l/Keycloak-fast-sso
   :alt: PyPI - License

   PyPI - License

keycloak-fast-sso
=================

``keycloakfastsso`` 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.

.. code:: python

   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.

.. code:: python

   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.

.. code:: python

   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:

.. code:: bash

   pip install keycloak-fast-sso

--------------

For more information on how to use this package, please refer to the
official documentation.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/alexandre-meline/keycloakfastsso",
    "name": "keycloak-fast-sso",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": "",
    "keywords": "keycloak fastapi sso",
    "author": "Alexandre Meline",
    "author_email": "alexandre.meline.dev@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/37/51/9f7a06081fd3dd15550696d1a1239caff34c40c5d22ed27621e5aafa9819/keycloak-fast-sso-2023.11.13.tar.gz",
    "platform": null,
    "description": ".. figure:: /docs/keycloakfastsso.png\n   :alt: keycloakfastsso\n\n   keycloakfastsso\n\n.. figure:: https://img.shields.io/pypi/l/Keycloak-fast-sso\n   :alt: PyPI - License\n\n   PyPI - License\n\nkeycloak-fast-sso\n=================\n\n``keycloakfastsso`` is a Python package that facilitates the integration\nof Keycloak authentication in applications built with the FastAPI web\nframework.\n\nFeatures \ud83c\udf81\n-----------\n\n-  Authentication with bearer JWT tokens.\n-  JWT token validation.\n-  Authorization based on roles, groups and the user\u2019s email\n   verification state in Keycloak.\n-  Provides information about the validated user.\n-  Handy tools for checking roles, groups and other user attributes.\n\nUsage \ud83d\udca1\n--------\n\nMiddleware\n~~~~~~~~~~\n\nUse KeycloakFastSSOMiddleware to protect your API routes. You must first\nconfigure the connection to Keycloak with the appropriate parameters.\n\n.. code:: python\n\n   from fastapi import FastAPI\n   from keycloakfastsso.middleware import KeycloakFastSSOMiddleware\n\n   app = FastAPI()\n   app.add_middleware( KeycloakFastSSOMiddleware,\n                       server_url=\"https://my-keycloak-url/auth/\",\n                       client_id=\"my-client-id\",\n                       realm_name=\"my-realm-name\",\n                       client_secret_key=\"my-client-secret-key\")\n\nDecorators\n~~~~~~~~~~\n\nThese decorators can be used to restrict access to routes based on user\nroles or groups.\n\n.. code:: python\n\n   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\n\n   @app.get(\"/require_role\")\n   @require_role([\"admin\"])\n   def require_role_endpoint(): \n       return {\"Hello\": \"World\"}\n\n   @app.get(\"/require_group\")\n   @require_group([\"my_group\"])\n   def require_group_endpoint(): \n       return {\"Hello\": \"World\"}\n\n   # other routes continue the same way \n\nUtilities\n~~~~~~~~~\n\nThe utilities allow you to retrieve specific information about the\ncurrently authenticated user.\n\n.. code:: python\n\n   from keycloakfastsso.utils import KeycloakUtils\n\n   # In your route\n   @app.get(\"/whoami\")\n   def who_am_i(request: Request):\n       return {\"user_id\": KeycloakUtils.get_user_id(request)}\n\nInstallation \ud83d\udee0\ufe0f\n---------------\n\nYou can install ``keycloakfastsso`` with pip:\n\n.. code:: bash\n\n   pip install keycloak-fast-sso\n\n--------------\n\nFor more information on how to use this package, please refer to the\nofficial documentation.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "FastAPI Keycloak SSO",
    "version": "2023.11.13",
    "project_urls": {
        "Homepage": "https://github.com/alexandre-meline/keycloakfastsso"
    },
    "split_keywords": [
        "keycloak",
        "fastapi",
        "sso"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "45fb7772f900ae252020ea5b053f513bbdb73e2c7b149d81b7409542efe2062d",
                "md5": "88e4bb92024365de262b5f63f6bd2ecf",
                "sha256": "498311e9187af68b554e9b6fb8328d42e8717a761ca142eb50ebc01a3b3e810c"
            },
            "downloads": -1,
            "filename": "keycloak_fast_sso-2023.11.13-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "88e4bb92024365de262b5f63f6bd2ecf",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 14103,
            "upload_time": "2023-11-06T00:43:15",
            "upload_time_iso_8601": "2023-11-06T00:43:15.390328Z",
            "url": "https://files.pythonhosted.org/packages/45/fb/7772f900ae252020ea5b053f513bbdb73e2c7b149d81b7409542efe2062d/keycloak_fast_sso-2023.11.13-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "37519f7a06081fd3dd15550696d1a1239caff34c40c5d22ed27621e5aafa9819",
                "md5": "4ccecf33aea56a9a0638d3efd1336256",
                "sha256": "10aff1d7b7492397f9b818883aedf3d64561b7c69e606da3ebbace8195e5c383"
            },
            "downloads": -1,
            "filename": "keycloak-fast-sso-2023.11.13.tar.gz",
            "has_sig": false,
            "md5_digest": "4ccecf33aea56a9a0638d3efd1336256",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 8716,
            "upload_time": "2023-11-06T00:43:17",
            "upload_time_iso_8601": "2023-11-06T00:43:17.025350Z",
            "url": "https://files.pythonhosted.org/packages/37/51/9f7a06081fd3dd15550696d1a1239caff34c40c5d22ed27621e5aafa9819/keycloak-fast-sso-2023.11.13.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-11-06 00:43:17",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "alexandre-meline",
    "github_project": "keycloakfastsso",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "keycloak-fast-sso"
}
        
Elapsed time: 0.13871s