diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..8b90ae2 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,41 @@ + +Changelog +============ + +All notable changes to this project will be documented in this file. + +## [0.5.0] - 2017-08-21 + +* Basic functions for Keycloak API (well_know, token, userinfo, logout, certs, +entitlement, instropect) + +## [0.6.0] - 2017-08-23 + +* Added load authorization settings + +## [0.7.0] - 2017-08-23 + +* Added polices + +## [0.8.0] - 2017-08-23 + +* Added permissions + +## [0.9.0] - 2017-09-05 + +* Added functions for Admin Keycloak API + +## [0.10.0] - 2017-10-23 + +* Updated libraries versions +* Updated Docs + +## [0.11.0] - 2017-12-12 + +* Changed Instropect RPT + +## [0.12.0] - 2018-01-25 + +* Add groups functions +* Add Admin Tasks for user and client role management +* Function to trigger user sync from provider \ No newline at end of file diff --git a/README.md b/README.md index a6d2811..ec9b7cd 100644 --- a/README.md +++ b/README.md @@ -204,4 +204,7 @@ group = keycloak_admin.get_group(group_id='group_id') # Get group by name group = keycloak_admin.get_group_by_name(name_or_path='group_id', search_in_subgroups=True) + +# Function to trigger user sync from provider +sync_users(storage_id="storage_di", action="action") ``` diff --git a/docs/source/conf.py b/docs/source/conf.py index c8f9890..ef6b6fe 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -60,9 +60,9 @@ author = 'Marcos Pereira' # built documents. # # The short X.Y version. -version = '0.11.1' +version = '0.12.0' # The full version, including alpha/beta/rc tags. -release = '0.11.1' +release = '0.12.0' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/docs/source/index.rst b/docs/source/index.rst index 9ce5594..eea1c71 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -73,14 +73,15 @@ Usage Main methods:: + # KEYCLOAK OPENID + 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", - verify=True) + client_secret_key="secret") # Get WellKnow config_well_know = keycloak_openid.well_know() @@ -91,6 +92,9 @@ Main methods:: # 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']) @@ -138,12 +142,26 @@ Main methods:: "realmRoles": ["user_default", ], "attributes": {"example": "1,2,3,3,"}}) + + # 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",}], + "realmRoles": ["user_default", ], + "attributes": {"example": "1,2,3,3,"}}) + # User counter count_users = keycloak_admin.users_count() # Get users Returns a list of users, filtered according to query parameters users = keycloak_admin.get_users({}) + # Get user ID from name + user-id-keycloak = keycloak_admin.get_user_id("example@example.com") + # Get User user = keycloak_admin.get_user("user-id-keycloak") @@ -151,6 +169,9 @@ Main methods:: response = keycloak_admin.update_user(user_id="user-id-keycloak", payload={'firstName': 'Example Update'}) + # Update User Password + response = set_user_password(user_id="user-id-keycloak", password="secret", temporary=True) + # Delete User response = keycloak_admin.delete_user(user_id="user-id-keycloak") @@ -177,19 +198,38 @@ Main methods:: client_id=keycloak_admin.get_client_id("my-client") # Get representation of the client - id of client (not client-id) - client_roles = keycloak_admin.get_client_role(client_id=client_id) + client = keycloak_admin.get_client(client_id="client_id") + + # Get all roles for the realm or client + realm_roles = keycloak_admin.get_realm_roles() # Get all roles for the client - client_roles = keycloak_admin.get_client_role(client_id=client_id) + client_roles = keycloak_admin.get_client_roles(client_id="client_id") - # Create client role - keycloak_admin.create_client_role(client_id, "test") + # Get client role + role = keycloak_admin.get_client_role(client_id="client_id", role_name="role_name") + # Warning: Deprecated # Get client role id from name - role_id = keycloak_admin.get_client_role_id(client_id=client_id, role_name="test") + role_id = keycloak_admin.get_client_role_id(client_id="client_id", role_name="test") - # Get all roles for the realm or client - realm_roles = keycloak_admin.get_roles() + # Create client role + keycloak_admin.create_client_role(client_id, "test") # Assign client role to user. Note that BOTH role_name and role_id appear to be required. - keycloak_admin.assign_client_role(client_id=client_id, user_id=user_id, role_id=role_id, role_name="test") + keycloak_admin.assign_client_role(client_id="client_id", user_id="user_id", role_id="role_id", role_name="test") + + # Create new group + group = keycloak_admin.create_group(name="Example Group") + + # Get all groups + groups = keycloak_admin.get_groups() + + # Get group + group = keycloak_admin.get_group(group_id='group_id') + + # Get group by name + group = keycloak_admin.get_group_by_name(name_or_path='group_id', search_in_subgroups=True) + + # Function to trigger user sync from provider + sync_users(storage_id="storage_di", action="action") diff --git a/keycloak/keycloak_admin.py b/keycloak/keycloak_admin.py index 4deb79c..068f29b 100644 --- a/keycloak/keycloak_admin.py +++ b/keycloak/keycloak_admin.py @@ -629,6 +629,13 @@ class KeycloakAdmin: return raise_error_from_response(data_raw, KeycloakGetError, expected_code=204) def sync_users(self, storage_id, action): + """ + Function to trigger user sync from provider + + :param storage_id: + :param action: + :return: + """ data = {'action': action} params_query = {"action": action}