You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

196 lines
5.6 KiB

9 months ago
  1. .. admin:
  2. Admin Client
  3. ========================
  4. Configure admin client
  5. -------------------------
  6. .. code-block:: python
  7. admin = KeycloakAdmin(
  8. server_url="http://localhost:8080/",
  9. username='example-admin',
  10. password='secret',
  11. realm_name="master",
  12. user_realm_name="only_if_other_realm_than_master")
  13. Configure admin client with connection
  14. --------------------------------------------------
  15. .. code-block:: python
  16. from keycloak import KeycloakAdmin
  17. from keycloak import KeycloakOpenIDConnection
  18. keycloak_connection = KeycloakOpenIDConnection(
  19. server_url="http://localhost:8080/",
  20. username='example-admin',
  21. password='secret',
  22. realm_name="master",
  23. user_realm_name="only_if_other_realm_than_master",
  24. client_id="my_client",
  25. client_secret_key="client-secret",
  26. verify=True)
  27. keycloak_admin = KeycloakAdmin(connection=keycloak_connection)
  28. Create user
  29. -------------------------
  30. .. code-block:: python
  31. new_user = keycloak_admin.create_user({"email": "example@example.com",
  32. "username": "example@example.com",
  33. "enabled": True,
  34. "firstName": "Example",
  35. "lastName": "Example"})
  36. Add user and raise exception if username already exists
  37. -----------------------------------------------------------
  38. The exist_ok currently defaults to True for backwards compatibility reasons.
  39. .. code-block:: python
  40. new_user = keycloak_admin.create_user({"email": "example@example.com",
  41. "username": "example@example.com",
  42. "enabled": True,
  43. "firstName": "Example",
  44. "lastName": "Example"},
  45. exist_ok=False)
  46. Add user and set password
  47. ---------------------------
  48. .. code-block:: python
  49. new_user = keycloak_admin.create_user({"email": "example@example.com",
  50. "username": "example@example.com",
  51. "enabled": True,
  52. "firstName": "Example",
  53. "lastName": "Example",
  54. "credentials": [{"value": "secret","type": "password",}]})
  55. Add user and specify a locale
  56. ------------------------------
  57. .. code-block:: python
  58. new_user = keycloak_admin.create_user({"email": "example@example.fr",
  59. "username": "example@example.fr",
  60. "enabled": True,
  61. "firstName": "Example",
  62. "lastName": "Example",
  63. "attributes": {
  64. "locale": ["fr"]
  65. }})
  66. User counter
  67. ------------------------------
  68. .. code-block:: python
  69. count_users = keycloak_admin.users_count()
  70. Get users Returns a list of users, filtered according to query parameters
  71. ----------------------------------------------------------------------------
  72. .. code-block:: python
  73. users = keycloak_admin.get_users({})
  74. Get user ID from username
  75. ------------------------------
  76. .. code-block:: python
  77. user_id_keycloak = keycloak_admin.get_user_id("username-keycloak")
  78. Get user
  79. ------------------------------
  80. .. code-block:: python
  81. user = keycloak_admin.get_user("user-id-keycloak")
  82. Update user
  83. ------------------------------
  84. .. code-block:: python
  85. response = keycloak_admin.update_user(user_id="user-id-keycloak",
  86. payload={'firstName': 'Example Update'})
  87. Update user password
  88. ------------------------------
  89. .. code-block:: python
  90. response = keycloak_admin.set_user_password(user_id="user-id-keycloak", password="secret", temporary=True)
  91. Get user credentials
  92. ------------------------------
  93. .. code-block:: python
  94. credentials = keycloak_admin.get_credentials(user_id='user_id')
  95. Get user credential by ID
  96. ------------------------------
  97. .. code-block:: python
  98. credential = keycloak_admin.get_credential(user_id='user_id', credential_id='credential_id')
  99. Delete user credential
  100. ------------------------------
  101. .. code-block:: python
  102. response = keycloak_admin.delete_credential(user_id='user_id', credential_id='credential_id')
  103. Delete User
  104. ------------------------------
  105. .. code-block:: python
  106. response = keycloak_admin.delete_user(user_id="user-id-keycloak")
  107. Get consents granted by the user
  108. --------------------------------
  109. .. code-block:: python
  110. consents = keycloak_admin.consents_user(user_id="user-id-keycloak")
  111. Send user action
  112. ------------------------------
  113. .. code-block:: python
  114. response = keycloak_admin.send_update_account(user_id="user-id-keycloak",
  115. payload=['UPDATE_PASSWORD'])
  116. Send verify email
  117. ------------------------------
  118. .. code-block:: python
  119. response = keycloak_admin.send_verify_email(user_id="user-id-keycloak")
  120. Get sessions associated with the user
  121. --------------------------------------
  122. .. code-block:: python
  123. sessions = keycloak_admin.get_sessions(user_id="user-id-keycloak")