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