From d5b48c2d68778b6b5c56148a5e890435f4878053 Mon Sep 17 00:00:00 2001 From: "Shon T. Urbas" Date: Wed, 6 Dec 2017 11:05:50 -0500 Subject: [PATCH 1/7] no need for simplejson --- keycloak/exceptions.py | 2 +- requirements.txt | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/keycloak/exceptions.py b/keycloak/exceptions.py index 95be231..8c422f7 100644 --- a/keycloak/exceptions.py +++ b/keycloak/exceptions.py @@ -16,7 +16,7 @@ # along with this program. If not, see . import requests -from simplejson import JSONDecodeError +from json import JSONDecodeError class KeycloakError(Exception): diff --git a/requirements.txt b/requirements.txt index bc7067a..61caa61 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,3 @@ -requests==2.18.3 +requests==2.18.4 httmock==1.2.5 python-jose==1.3.2 -simplejson \ No newline at end of file From bd06ace4c2374bea08fcda02719732e3125aab62 Mon Sep 17 00:00:00 2001 From: "Shon T. Urbas" Date: Wed, 6 Dec 2017 11:06:49 -0500 Subject: [PATCH 2/7] revert to payload --- keycloak/keycloak_admin.py | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/keycloak/keycloak_admin.py b/keycloak/keycloak_admin.py index c24dbc3..67fefcf 100644 --- a/keycloak/keycloak_admin.py +++ b/keycloak/keycloak_admin.py @@ -106,7 +106,7 @@ class KeycloakAdmin: data_raw = self.connection.raw_get(URL_ADMIN_USERS.format(**params_path), **query) return raise_error_from_response(data_raw, KeycloakGetError) - def create_user(self, username, email='', firstName='', lastName='', emailVerified=False, enabled=True): + def create_user(self, payload): """ Create a new user Username must be unique @@ -115,17 +115,11 @@ class KeycloakAdmin: :param payload: UserRepresentation + :return: UserRepresentation """ - data={} - data["username"]=username - data["email"]=email - data["firstName"]=firstName - data["lastName"]=lastName - data["emailVerified"]=emailVerified - data["enabled"]=enabled params_path = {"realm-name": self.realm_name} data_raw = self.connection.raw_post(URL_ADMIN_USERS.format(**params_path), - data=json.dumps(data)) + data=json.dumps(payload)) return raise_error_from_response(data_raw, KeycloakGetError, expected_code=201) def users_count(self): @@ -138,7 +132,6 @@ class KeycloakAdmin: data_raw = self.connection.raw_get(URL_ADMIN_USERS_COUNT.format(**params_path)) return raise_error_from_response(data_raw, KeycloakGetError) - def get_user_id(self, username): """ Get internal keycloak user id from username @@ -184,14 +177,9 @@ class KeycloakAdmin: :return: Http response """ - data={} - data["username"]=username - data["email"]=email - data["firstName"]=firstName - data["lastName"]=lastName - data["emailVerified"]=emailVerified - data["enabled"]=enabled - params_path = {"realm-name": self.realm_name} + data = {"username": username, "email": email, "firstName": firstName, "lastName": lastName, + "emailVerified": emailVerified, "enabled": enabled} + params_path = {"realm-name": self.realm_name, "id": user_id} data_raw = self.connection.raw_put(URL_ADMIN_USER.format(**params_path), data=json.dumps(data)) From fb4ce0045491c9f26a25373bd0668ff9863797a1 Mon Sep 17 00:00:00 2001 From: "Shon T. Urbas" Date: Wed, 6 Dec 2017 11:52:12 -0500 Subject: [PATCH 3/7] revert back to payload --- keycloak/keycloak_admin.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/keycloak/keycloak_admin.py b/keycloak/keycloak_admin.py index 67fefcf..6c9e32b 100644 --- a/keycloak/keycloak_admin.py +++ b/keycloak/keycloak_admin.py @@ -168,7 +168,7 @@ class KeycloakAdmin: data_raw = self.connection.raw_get(URL_ADMIN_USER.format(**params_path)) return raise_error_from_response(data_raw, KeycloakGetError) - def update_user(self, user_id, username, email='', firstName='', lastName='', emailVerified=False, enabled=True): + def update_user(self, user_id, payload): """ Update the user @@ -177,12 +177,9 @@ class KeycloakAdmin: :return: Http response """ - data = {"username": username, "email": email, "firstName": firstName, "lastName": lastName, - "emailVerified": emailVerified, "enabled": enabled} - params_path = {"realm-name": self.realm_name, "id": user_id} data_raw = self.connection.raw_put(URL_ADMIN_USER.format(**params_path), - data=json.dumps(data)) + data=json.dumps(payload)) return raise_error_from_response(data_raw, KeycloakGetError, expected_code=204) def delete_user(self, user_id): From 944e2a7a39644c2863cfd7c9f3381de1dea614ba Mon Sep 17 00:00:00 2001 From: "Shon T. Urbas" Date: Wed, 6 Dec 2017 14:25:16 -0500 Subject: [PATCH 4/7] A decoder error is a ValueError allows us to catch all decode errors from requests without force install simplejson --- keycloak/exceptions.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/keycloak/exceptions.py b/keycloak/exceptions.py index 8c422f7..27d8b14 100644 --- a/keycloak/exceptions.py +++ b/keycloak/exceptions.py @@ -16,7 +16,6 @@ # along with this program. If not, see . import requests -from json import JSONDecodeError class KeycloakError(Exception): @@ -73,10 +72,9 @@ def raise_error_from_response(response, error, expected_code=200): if expected_code == response.status_code: if expected_code == requests.codes.no_content: return {} - try: return response.json() - except JSONDecodeError as e: + except ValueError: return response.content try: From 418e1bddf59c7cafd0eb01e1e70b4479e501662e Mon Sep 17 00:00:00 2001 From: Marcos Pereira Date: Tue, 12 Dec 2017 16:13:18 -0200 Subject: [PATCH 5/7] Release 0.11.0 --- README.md | 2 +- docs/source/conf.py | 4 ++-- docs/source/index.rst | 6 +++--- setup.py | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index a80448a..ef8e01f 100644 --- a/README.md +++ b/README.md @@ -74,7 +74,7 @@ token = keycloak_openid.token("user", "password") rpt = keycloak_openid.entitlement(token['access_token'], "resource_id") # Instropect RPT -token_rpt_info = keycloak_openid.instropect(keycloak_openid.instropect(token['access_token'], rpt=rpt['rpt'], +token_rpt_info = keycloak_openid.introspect(keycloak_openid.introspect(token['access_token'], rpt=rpt['rpt'], token_type_hint="requesting_party_token")) # Introspect Token diff --git a/docs/source/conf.py b/docs/source/conf.py index b5eba8c..1e7cf48 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.10.2' +version = '0.11.0' # The full version, including alpha/beta/rc tags. -release = '0.10.2' +release = '0.11.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 f68dcbb..9ce5594 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -43,7 +43,6 @@ python-keycloak depends on: * Python 3 * `requests `_ * `python-jose `_ -* `simplejson `_ Tests Dependencies ------------------ @@ -67,6 +66,7 @@ Contributors * `Agriness Team `_ * `Martin Devlin `_ +* `Shon T. Urbas `_ Usage ===== @@ -102,7 +102,7 @@ Main methods:: rpt = keycloak_openid.entitlement(token['access_token'], "resource_id") # Instropect RPT - token_rpt_info = keycloak_openid.instropect(keycloak_openid.instropect(token['access_token'], rpt=rpt['rpt'], + token_rpt_info = keycloak_openid.introspect(keycloak_openid.introspect(token['access_token'], rpt=rpt['rpt'], token_type_hint="requesting_party_token")) # Introspect Token @@ -127,7 +127,7 @@ Main methods:: username='example-admin', password='secret', realm_name="example_realm", - verify=True) + verify=True) # Add user new_user = keycloak_admin.create_user({"email": "example@example.com", diff --git a/setup.py b/setup.py index ed1df7f..7746d82 100644 --- a/setup.py +++ b/setup.py @@ -4,7 +4,7 @@ from setuptools import setup setup( name='python-keycloak', - version='0.10.2', + version='0.11.0', url='https://bitbucket.org/agriness/python-keycloak', license='GNU General Public License - V3', author='Marcos Pereira', @@ -12,7 +12,7 @@ setup( keywords='keycloak openid', description=u'python-keycloak is a Python package providing access to the Keycloak API.', packages=['keycloak', 'keycloak.authorization', 'keycloak.tests'], - install_requires=['requests==2.18.3', 'httmock==1.2.5', 'python-jose==1.3.2', 'simplejson'], + install_requires=['requests==2.18.4', 'httmock==1.2.5', 'python-jose==1.3.2', 'simplejson'], classifiers=[ 'Programming Language :: Python :: 3', 'License :: OSI Approved :: GNU General Public License v3 (GPLv3)', From 6b54b60e70e8b6d15e5057b6fc73e5116907117e Mon Sep 17 00:00:00 2001 From: Marcos Pereira Date: Tue, 12 Dec 2017 17:03:02 -0200 Subject: [PATCH 6/7] Updated readme. --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index ef8e01f..c4a8c32 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,7 @@ The documentation for python-keycloak is available on [readthedocs](http://pytho * [Agriness Team](http://www.agriness.com/pt/) * [Martin Devlin](martin.devlin@pearson.com) +* [Shon T. Urbas](shon.urbas@gmail.com>) ## Usage From 0554a333da3c506c26290d10932859a58f544031 Mon Sep 17 00:00:00 2001 From: Marcos Pereira Date: Tue, 12 Dec 2017 17:08:07 -0200 Subject: [PATCH 7/7] Updated readme. --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index c4a8c32..239436c 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,7 @@ The documentation for python-keycloak is available on [readthedocs](http://pytho ## Contributors * [Agriness Team](http://www.agriness.com/pt/) +* [Marcos Pereira](marcospereira.mpj@gmail.com) * [Martin Devlin](martin.devlin@pearson.com) * [Shon T. Urbas](shon.urbas@gmail.com>)