From 74da5c2ee6becde47aa37284a313a29623743077 Mon Sep 17 00:00:00 2001 From: Alain ROMEYER Date: Thu, 22 Nov 2018 16:12:58 +0100 Subject: [PATCH 1/2] support totp --- keycloak/keycloak_openid.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/keycloak/keycloak_openid.py b/keycloak/keycloak_openid.py index ca4d9ae..24e9707 100644 --- a/keycloak/keycloak_openid.py +++ b/keycloak/keycloak_openid.py @@ -158,7 +158,7 @@ class KeycloakOpenID: """ return NotImplemented - def token(self, username="", password="", grant_type=["password"], code="", redirect_uri=""): + def token(self, username="", password="", grant_type=["password"], code="", redirect_uri="", totp=None): """ The token endpoint is used to obtain tokens. Tokens can either be obtained by exchanging an authorization code or by supplying credentials directly depending on @@ -172,6 +172,7 @@ class KeycloakOpenID: :param grant_type: :param code: :param redirect_uri + :param totp :return: """ params_path = {"realm-name": self.realm_name} @@ -179,6 +180,9 @@ class KeycloakOpenID: "client_id": self.client_id, "grant_type": grant_type, "code": code, "redirect_uri": redirect_uri} + if totp: + payload["totp"] = totp + payload = self._add_secret_key(payload) data_raw = self.connection.raw_post(URL_TOKEN.format(**params_path), data=payload) From 5f981d4de87a12fbce18f38413058061b1ba60d8 Mon Sep 17 00:00:00 2001 From: Alain ROMEYER Date: Wed, 5 Dec 2018 09:56:10 +0100 Subject: [PATCH 2/2] add an example on how to get a token with user+password+totp --- README.md | 1 + docs/source/index.rst | 1 + 2 files changed, 2 insertions(+) diff --git a/README.md b/README.md index 990ef71..b79147d 100644 --- a/README.md +++ b/README.md @@ -69,6 +69,7 @@ config_well_know = keycloak_openid.well_know() # Get Token token = keycloak_openid.token("user", "password") +token = keycloak_openid.token("user", "password", totp="012345") # Get Userinfo userinfo = keycloak_openid.userinfo(token['access_token']) diff --git a/docs/source/index.rst b/docs/source/index.rst index e105a03..1123ddd 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -97,6 +97,7 @@ Main methods:: # Get Token token = keycloak_openid.token("user", "password") + token = keycloak_openid.token("user", "password", totp="012345") # Get Userinfo userinfo = keycloak_openid.userinfo(token['access_token'])