Browse Source

Merge pull request #245 from ziyunxiao/master

fix invalid credential error and refresh_code not exist error
pull/247/head^2
Marcos Pereira 3 years ago
committed by GitHub
parent
commit
26cb5679ea
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 14
      keycloak/keycloak_admin.py

14
keycloak/keycloak_admin.py

@ -2106,7 +2106,13 @@ class KeycloakAdmin:
return r return r
def get_token(self): def get_token(self):
token_realm_name = self.user_realm_name or self.realm_name
if self.user_realm_name:
token_realm_name = self.user_realm_name
elif self.realm_name:
token_realm_name = self.realm_name
else:
token_realm_name = "master"
self.keycloak_openid = KeycloakOpenID(server_url=self.server_url, client_id=self.client_id, self.keycloak_openid = KeycloakOpenID(server_url=self.server_url, client_id=self.client_id,
realm_name=token_realm_name, verify=self.verify, realm_name=token_realm_name, verify=self.verify,
client_secret_key=self.client_secret_key, client_secret_key=self.client_secret_key,
@ -2139,7 +2145,10 @@ class KeycloakAdmin:
verify=self.verify) verify=self.verify)
def refresh_token(self): def refresh_token(self):
refresh_token = self.token.get('refresh_token')
refresh_token = self.token.get('refresh_token', None)
if refresh_token is None:
self.get_token()
else:
try: try:
self.token = self.keycloak_openid.refresh_token(refresh_token) self.token = self.keycloak_openid.refresh_token(refresh_token)
except KeycloakGetError as e: except KeycloakGetError as e:
@ -2152,6 +2161,7 @@ class KeycloakAdmin:
self.get_token() self.get_token()
else: else:
raise raise
self.connection.add_param_headers('Authorization', 'Bearer ' + self.token.get('access_token')) self.connection.add_param_headers('Authorization', 'Bearer ' + self.token.get('access_token'))
def get_client_all_sessions(self, client_id): def get_client_all_sessions(self, client_id):

Loading…
Cancel
Save