python-keycloak


Namepython-keycloak JSON
Version 3.12.0 PyPI version JSON
download
home_pageNone
Summarypython-keycloak is a Python package providing access to the Keycloak API.
upload_time2024-04-10 07:16:03
maintainerNone
docs_urlNone
authorMarcos Pereira
requires_python<4.0,>=3.8
licenseMIT
keywords keycloak openid oidc
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            [![CircleCI](https://github.com/marcospereirampj/python-keycloak/actions/workflows/daily.yaml/badge.svg)](https://github.com/marcospereirampj/python-keycloak/)
[![Documentation Status](https://readthedocs.org/projects/python-keycloak/badge/?version=latest)](http://python-keycloak.readthedocs.io/en/latest/?badge=latest)

# Python Keycloak

**python-keycloak** is a Python package providing access to the Keycloak API.

## Installation

Install via PyPI:

`$ pip install python-keycloak`

## Bug reports

Please report bugs and feature requests at
https://github.com/marcospereirampj/python-keycloak/issues

## Documentation

The documentation for python-keycloak is available on [readthedocs](http://python-keycloak.readthedocs.io).

## Example of Using Keycloak OpenID



```python
from keycloak import KeycloakOpenID

# Configure client
keycloak_openid = KeycloakOpenID(server_url="http://localhost:8080/auth/",
                                 client_id="example_client",
                                 realm_name="example_realm",
                                 client_secret_key="secret")

# Get WellKnown
config_well_known = keycloak_openid.well_known()

# Get Code With Oauth Authorization Request
auth_url = keycloak_openid.auth_url(
    redirect_uri="your_call_back_url",
    scope="email",
    state="your_state_info")

# Get Access Token With Code
access_token = keycloak_openid.token(
    grant_type='authorization_code',
    code='the_code_you_get_from_auth_url_callback',
    redirect_uri="your_call_back_url")


# Get Token
token = keycloak_openid.token("user", "password")
token = keycloak_openid.token("user", "password", totp="012345")

# Get token using Token Exchange
token = keycloak_openid.exchange_token(token['access_token'], "my_client", "other_client", "some_user")

# Get Userinfo
userinfo = keycloak_openid.userinfo(token['access_token'])

# Refresh token
token = keycloak_openid.refresh_token(token['refresh_token'])

# Logout
keycloak_openid.logout(token['refresh_token'])
```

## Example of Using Keycloak Admin API

```python
from keycloak import KeycloakAdmin
from keycloak import KeycloakOpenIDConnection

keycloak_connection = KeycloakOpenIDConnection(
                        server_url="http://localhost:8080/",
                        username='example-admin',
                        password='secret',
                        realm_name="master",
                        user_realm_name="only_if_other_realm_than_master",
                        client_id="my_client",
                        client_secret_key="client-secret",
                        verify=True)

keycloak_admin = KeycloakAdmin(connection=keycloak_connection)

# Add user
new_user = keycloak_admin.create_user({"email": "example@example.com",
                                       "username": "example@example.com",
                                       "enabled": True,
                                       "firstName": "Example",
                                       "lastName": "Example"})

# Add user and raise exception if username already exists
# exist_ok currently defaults to True for backwards compatibility reasons
new_user = keycloak_admin.create_user({"email": "example@example.com",
                                       "username": "example@example.com",
                                       "enabled": True,
                                       "firstName": "Example",
                                       "lastName": "Example"},
                                      exist_ok=False)

# Add user and set password
new_user = keycloak_admin.create_user({"email": "example@example.com",
                                       "username": "example@example.com",
                                       "enabled": True,
                                       "firstName": "Example",
                                       "lastName": "Example",
                    "credentials": [{"value": "secret","type": "password",}]})
```

For more details, see the documentation available on [readthedocs](http://python-keycloak.readthedocs.io).


            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "python-keycloak",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.8",
    "maintainer_email": null,
    "keywords": "keycloak, openid, oidc",
    "author": "Marcos Pereira",
    "author_email": "marcospereira.mpj@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/21/13/1587ae369e08e964f152e44ce6330c2315c7f28b8477d04ef4e67a9c03a3/python_keycloak-3.12.0.tar.gz",
    "platform": null,
    "description": "[![CircleCI](https://github.com/marcospereirampj/python-keycloak/actions/workflows/daily.yaml/badge.svg)](https://github.com/marcospereirampj/python-keycloak/)\n[![Documentation Status](https://readthedocs.org/projects/python-keycloak/badge/?version=latest)](http://python-keycloak.readthedocs.io/en/latest/?badge=latest)\n\n# Python Keycloak\n\n**python-keycloak** is a Python package providing access to the Keycloak API.\n\n## Installation\n\nInstall via PyPI:\n\n`$ pip install python-keycloak`\n\n## Bug reports\n\nPlease report bugs and feature requests at\nhttps://github.com/marcospereirampj/python-keycloak/issues\n\n## Documentation\n\nThe documentation for python-keycloak is available on [readthedocs](http://python-keycloak.readthedocs.io).\n\n## Example of Using Keycloak OpenID\n\n\n\n```python\nfrom keycloak import KeycloakOpenID\n\n# Configure client\nkeycloak_openid = KeycloakOpenID(server_url=\"http://localhost:8080/auth/\",\n                                 client_id=\"example_client\",\n                                 realm_name=\"example_realm\",\n                                 client_secret_key=\"secret\")\n\n# Get WellKnown\nconfig_well_known = keycloak_openid.well_known()\n\n# Get Code With Oauth Authorization Request\nauth_url = keycloak_openid.auth_url(\n    redirect_uri=\"your_call_back_url\",\n    scope=\"email\",\n    state=\"your_state_info\")\n\n# Get Access Token With Code\naccess_token = keycloak_openid.token(\n    grant_type='authorization_code',\n    code='the_code_you_get_from_auth_url_callback',\n    redirect_uri=\"your_call_back_url\")\n\n\n# Get Token\ntoken = keycloak_openid.token(\"user\", \"password\")\ntoken = keycloak_openid.token(\"user\", \"password\", totp=\"012345\")\n\n# Get token using Token Exchange\ntoken = keycloak_openid.exchange_token(token['access_token'], \"my_client\", \"other_client\", \"some_user\")\n\n# Get Userinfo\nuserinfo = keycloak_openid.userinfo(token['access_token'])\n\n# Refresh token\ntoken = keycloak_openid.refresh_token(token['refresh_token'])\n\n# Logout\nkeycloak_openid.logout(token['refresh_token'])\n```\n\n## Example of Using Keycloak Admin API\n\n```python\nfrom keycloak import KeycloakAdmin\nfrom keycloak import KeycloakOpenIDConnection\n\nkeycloak_connection = KeycloakOpenIDConnection(\n                        server_url=\"http://localhost:8080/\",\n                        username='example-admin',\n                        password='secret',\n                        realm_name=\"master\",\n                        user_realm_name=\"only_if_other_realm_than_master\",\n                        client_id=\"my_client\",\n                        client_secret_key=\"client-secret\",\n                        verify=True)\n\nkeycloak_admin = KeycloakAdmin(connection=keycloak_connection)\n\n# Add user\nnew_user = keycloak_admin.create_user({\"email\": \"example@example.com\",\n                                       \"username\": \"example@example.com\",\n                                       \"enabled\": True,\n                                       \"firstName\": \"Example\",\n                                       \"lastName\": \"Example\"})\n\n# Add user and raise exception if username already exists\n# exist_ok currently defaults to True for backwards compatibility reasons\nnew_user = keycloak_admin.create_user({\"email\": \"example@example.com\",\n                                       \"username\": \"example@example.com\",\n                                       \"enabled\": True,\n                                       \"firstName\": \"Example\",\n                                       \"lastName\": \"Example\"},\n                                      exist_ok=False)\n\n# Add user and set password\nnew_user = keycloak_admin.create_user({\"email\": \"example@example.com\",\n                                       \"username\": \"example@example.com\",\n                                       \"enabled\": True,\n                                       \"firstName\": \"Example\",\n                                       \"lastName\": \"Example\",\n                    \"credentials\": [{\"value\": \"secret\",\"type\": \"password\",}]})\n```\n\nFor more details, see the documentation available on [readthedocs](http://python-keycloak.readthedocs.io).\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "python-keycloak is a Python package providing access to the Keycloak API.",
    "version": "3.12.0",
    "project_urls": {
        "Documentation": "https://python-keycloak.readthedocs.io/en/latest/",
        "Issue tracker": "https://github.com/marcospereirampj/python-keycloak/issues"
    },
    "split_keywords": [
        "keycloak",
        " openid",
        " oidc"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "dfafd7b2ac2ef402a34a39b135a060befdb73f57d8a12dcaf11a564f3b71f361",
                "md5": "3a3ef598250467f13ff4a813687f3a9e",
                "sha256": "e8073515e6b47500cf0bda0d7eb8dd0cd2e83fa537196aed7c359dec15a2ee81"
            },
            "downloads": -1,
            "filename": "python_keycloak-3.12.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "3a3ef598250467f13ff4a813687f3a9e",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.8",
            "size": 59045,
            "upload_time": "2024-04-10T07:15:59",
            "upload_time_iso_8601": "2024-04-10T07:15:59.962325Z",
            "url": "https://files.pythonhosted.org/packages/df/af/d7b2ac2ef402a34a39b135a060befdb73f57d8a12dcaf11a564f3b71f361/python_keycloak-3.12.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "21131587ae369e08e964f152e44ce6330c2315c7f28b8477d04ef4e67a9c03a3",
                "md5": "926765d2b0ffb628a4d83062637847de",
                "sha256": "21dec81992db192a462a6f12b792fd1c84d18d9bf5e91dea033a46e6f51b6694"
            },
            "downloads": -1,
            "filename": "python_keycloak-3.12.0.tar.gz",
            "has_sig": false,
            "md5_digest": "926765d2b0ffb628a4d83062637847de",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.8",
            "size": 44629,
            "upload_time": "2024-04-10T07:16:03",
            "upload_time_iso_8601": "2024-04-10T07:16:03.052614Z",
            "url": "https://files.pythonhosted.org/packages/21/13/1587ae369e08e964f152e44ce6330c2315c7f28b8477d04ef4e67a9c03a3/python_keycloak-3.12.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-10 07:16:03",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "marcospereirampj",
    "github_project": "python-keycloak",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "python-keycloak"
}
        
Elapsed time: 0.23715s