Browse Source

Merged in aromeyer/python-keycloak/feature/add-totp-support (pull request #24)

Add totp support

Approved-by: Marcos Pereira <marcospereira.mpj@gmail.com>
pull/12/head
Alain ROMEYER 6 years ago
committed by Marcos Pereira
parent
commit
e698b2aa42
  1. 1
      README.md
  2. 1
      docs/source/index.rst
  3. 6
      keycloak/keycloak_openid.py

1
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'])

1
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'])

6
keycloak/keycloak_openid.py

@ -162,7 +162,7 @@ class KeycloakOpenID:
"redirect-uri": redirect_uri}
return URL_AUTH.format(**params_path)
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
@ -176,6 +176,7 @@ class KeycloakOpenID:
:param grant_type:
:param code:
:param redirect_uri
:param totp
:return:
"""
params_path = {"realm-name": self.realm_name}
@ -183,6 +184,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)

Loading…
Cancel
Save