Lucy Linder
12 months ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with
33 additions and
1 deletions
-
README.md
-
src/keycloak/keycloak_admin.py
-
tests/test_keycloak_admin.py
|
@ -340,9 +340,12 @@ keycloak_admin.get_client_roles_of_client_scope(client_id=another_client_id, cli |
|
|
# Remove client roles assigned to client's scope |
|
|
# Remove client roles assigned to client's scope |
|
|
keycloak_admin.delete_client_roles_of_client_scope(client_id=another_client_id, client_roles_owner_id=client_id, roles=client_roles) |
|
|
keycloak_admin.delete_client_roles_of_client_scope(client_id=another_client_id, client_roles_owner_id=client_id, roles=client_roles) |
|
|
|
|
|
|
|
|
# Get all ID Providers |
|
|
|
|
|
|
|
|
# Get all IDP Providers |
|
|
idps = keycloak_admin.get_idps() |
|
|
idps = keycloak_admin.get_idps() |
|
|
|
|
|
|
|
|
|
|
|
# Get a specific IDP Provider, using its alias |
|
|
|
|
|
idp = keycloak_admin.get_idp("idp-alias") |
|
|
|
|
|
|
|
|
# Create a new Realm |
|
|
# Create a new Realm |
|
|
keycloak_admin.create_realm(payload={"realm": "demo"}, skip_exists=False) |
|
|
keycloak_admin.create_realm(payload={"realm": "demo"}, skip_exists=False) |
|
|
|
|
|
|
|
|
|
@ -773,6 +773,23 @@ class KeycloakAdmin: |
|
|
data_raw = self.connection.raw_get(urls_patterns.URL_ADMIN_IDPS.format(**params_path)) |
|
|
data_raw = self.connection.raw_get(urls_patterns.URL_ADMIN_IDPS.format(**params_path)) |
|
|
return raise_error_from_response(data_raw, KeycloakGetError) |
|
|
return raise_error_from_response(data_raw, KeycloakGetError) |
|
|
|
|
|
|
|
|
|
|
|
def get_idp(self, idp_alias): |
|
|
|
|
|
"""Get IDP provider. |
|
|
|
|
|
|
|
|
|
|
|
Get the representation of a specific IDP Provider. |
|
|
|
|
|
|
|
|
|
|
|
IdentityProviderRepresentation |
|
|
|
|
|
https://www.keycloak.org/docs-api/18.0/rest-api/index.html#_identityproviderrepresentation |
|
|
|
|
|
|
|
|
|
|
|
:param: idp_alias: alias for IdP to get |
|
|
|
|
|
:type idp_alias: str |
|
|
|
|
|
:return: IdentityProviderRepresentation |
|
|
|
|
|
:rtype: dict |
|
|
|
|
|
""" |
|
|
|
|
|
params_path = {"realm-name": self.connection.realm_name, "alias": idp_alias} |
|
|
|
|
|
data_raw = self.connection.raw_get(urls_patterns.URL_ADMIN_IDP.format(**params_path)) |
|
|
|
|
|
return raise_error_from_response(data_raw, KeycloakGetError) |
|
|
|
|
|
|
|
|
def delete_idp(self, idp_alias): |
|
|
def delete_idp(self, idp_alias): |
|
|
"""Delete an ID Provider. |
|
|
"""Delete an ID Provider. |
|
|
|
|
|
|
|
|
|
@ -395,6 +395,18 @@ def test_idps(admin: KeycloakAdmin, realm: str): |
|
|
assert len(idps) == 1 |
|
|
assert len(idps) == 1 |
|
|
assert "github" == idps[0]["alias"] |
|
|
assert "github" == idps[0]["alias"] |
|
|
|
|
|
|
|
|
|
|
|
# Test get idp |
|
|
|
|
|
idp = admin.get_idp("github") |
|
|
|
|
|
assert "github" == idp["alias"] |
|
|
|
|
|
assert idp.get("config") |
|
|
|
|
|
assert "test" == idp["config"]["clientId"] |
|
|
|
|
|
assert "**********" == idp["config"]["clientSecret"] |
|
|
|
|
|
|
|
|
|
|
|
# Test get idp fail |
|
|
|
|
|
with pytest.raises(KeycloakGetError) as err: |
|
|
|
|
|
admin.get_idp("does-not-exist") |
|
|
|
|
|
assert err.match('404: b\'{"error":"HTTP 404 Not Found"}\'') |
|
|
|
|
|
|
|
|
# Test IdP update |
|
|
# Test IdP update |
|
|
res = admin.update_idp(idp_alias="github", payload=idps[0]) |
|
|
res = admin.update_idp(idp_alias="github", payload=idps[0]) |
|
|
|
|
|
|
|
|