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.

91 lines
2.4 KiB

7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
  1. [![Documentation Status](https://readthedocs.org/projects/python-keycloak/badge/?version=latest)](http://python-keycloak.readthedocs.io/en/latest/?badge=latest)
  2. Python Keycloak
  3. ====================
  4. **python-keycloak** is a Python package providing access to the Keycloak API.
  5. ## Installation
  6. ### Via Pypi Package:
  7. ``` $ pip install python-keycloak ```
  8. ### Manually
  9. ``` $ python setup.py install ```
  10. ## Dependencies
  11. python-keycloak depends on:
  12. * Python 3
  13. * [requests](http://docs.python-requests.org/en/master/)
  14. * [python-jose](http://python-jose.readthedocs.io/en/latest/)
  15. ### Tests Dependencies
  16. * unittest
  17. * [httmock](https://github.com/patrys/httmock)
  18. ## Bug reports
  19. Please report bugs and feature requests at
  20. https://bitbucket.org/agriness/python-keycloak/issues
  21. ## Documentation
  22. The documentation for python-keycloak is available on [readthedocs](http://python-keycloak.readthedocs.io).
  23. ## Contributors
  24. * [Agriness Team](http://www.agriness.com/pt/)
  25. ## Usage
  26. ```python
  27. from keycloak import Keycloak
  28. # Configure client
  29. keycloak = Keycloak(server_url="http://localhost:8080/auth/",
  30. client_id="example_client",
  31. realm_name="example_realm",
  32. client_secret_key="secret")
  33. # Get WellKnow
  34. config_well_know = keycloak.well_know()
  35. # Get Token
  36. token = keycloak.token("user", "password")
  37. # Get Userinfo
  38. userinfo = keycloak.userinfo(token['access_token'])
  39. # Logout
  40. keycloak.logout(token['refresh_token'])
  41. # Get Certs
  42. certs = keycloak.certs()
  43. # Get RPT (Entitlement)
  44. token = keycloak.token("user", "password")
  45. rpt = keycloak.entitlement(token['access_token'], "resource_id")
  46. # Instropect RPT
  47. token_rpt_info = keycloak.instropect(keycloak.instropect(token['access_token'], rpt=rpt['rpt'],
  48. token_type_hint="requesting_party_token"))
  49. # Introspect Token
  50. token_info = keycloak.introspect(token['access_token']))
  51. # Decode Token
  52. KEYCLOAK_PUBLIC_KEY = "secret"
  53. options = {"verify_signature": True, "verify_aud": True, "exp": True}
  54. token_info = keycloak.decode_token(token['access_token'], key=KEYCLOAK_PUBLIC_KEY, options=options)
  55. # Get permissions by token
  56. token = keycloak.token("user", "password")
  57. keycloak.load_authorization_config("example-authz-config.json")
  58. policies = keycloak.get_policies(token['access_token'], method_token_info='decode', key=KEYCLOAK_PUBLIC_KEY)
  59. permissions = keycloak.get_permissions(token['access_token'], method_token_info='introspect')
  60. ```