Browse Source

Merge pull request #302 from asyd/issue/257

Add support of TOTP to KeycloakAdmin
pull/312/head
Richard Nemeth 3 years ago
committed by GitHub
parent
commit
e68114ab35
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 18
      keycloak/keycloak_admin.py

18
keycloak/keycloak_admin.py

@ -65,6 +65,7 @@ class KeycloakAdmin:
_server_url = None
_username = None
_password = None
_totp = None
_realm_name = None
_client_id = None
_verify = None
@ -75,13 +76,14 @@ class KeycloakAdmin:
_custom_headers = None
_user_realm_name = None
def __init__(self, server_url, username=None, password=None, realm_name='master', client_id='admin-cli', verify=True,
client_secret_key=None, custom_headers=None, user_realm_name=None, auto_refresh_token=None):
def __init__(self, server_url, username=None, password=None, totp=None, realm_name='master', client_id='admin-cli',
verify=True, client_secret_key=None, custom_headers=None, user_realm_name=None, auto_refresh_token=None):
"""
:param server_url: Keycloak server url
:param username: admin username
:param password: admin password
:param totp: Time based OTP
:param realm_name: realm name
:param client_id: client id
:param verify: True if want check connection SSL
@ -93,6 +95,7 @@ class KeycloakAdmin:
self.server_url = server_url
self.username = username
self.password = password
self.totp = totp
self.realm_name = realm_name
self.client_id = client_id
self.verify = verify
@ -168,6 +171,14 @@ class KeycloakAdmin:
def password(self, value):
self._password = value
@property
def totp(self):
return self._totp
@totp.setter
def totp(self, value):
self._totp = value
@property
def token(self):
return self._token
@ -2286,7 +2297,8 @@ class KeycloakAdmin:
self.realm_name = self.user_realm_name
if self.username and self.password:
self._token = self.keycloak_openid.token(self.username, self.password, grant_type=grant_type)
self._token = self.keycloak_openid.token(self.username, self.password,
grant_type=grant_type, totp=self.totp)
headers = {
'Authorization': 'Bearer ' + self.token.get('access_token'),

Loading…
Cancel
Save