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.

118 lines
3.1 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
  1. .. python-keycloak documentation master file, created by
  2. sphinx-quickstart on Tue Aug 15 11:02:59 2017.
  3. You can adapt this file completely to your liking, but it should at least
  4. contain the root `toctree` directive.
  5. .. toctree::
  6. :maxdepth: 2
  7. :caption: Contents:
  8. Indices and tables
  9. ==================
  10. * :ref:`genindex`
  11. * :ref:`modindex`
  12. * :ref:`search`
  13. .. image:: https://readthedocs.org/projects/python-keycloak/badge/?version=latest
  14. :target: http://python-keycloak.readthedocs.io/en/latest/?badge=latest
  15. Welcome to python-keycloak's documentation!
  16. ===========================================
  17. **python-keycloak** is a Python package providing access to the Keycloak API.
  18. Installation
  19. ==================
  20. Via Pypi Package::
  21. $ pip install python-keycloak
  22. Manually::
  23. $ python setup.py install
  24. Dependencies
  25. ==================
  26. python-keycloak depends on:
  27. * Python 3
  28. * `requests <http://docs.python-requests.org/en/master/>`_
  29. * `python-jose <http://python-jose.readthedocs.io/en/latest/>`_
  30. Tests Dependencies
  31. ------------------
  32. * unittest
  33. * `httmock <https://github.com/patrys/httmock>`_
  34. Bug reports
  35. ==================
  36. Please report bugs and feature requests at
  37. `https://bitbucket.org/agriness/python-keycloak/issues <https://bitbucket.org/agriness/python-keycloak/issues>`_
  38. Documentation
  39. ==================
  40. The documentation for python-keycloak is available on `readthedocs <http://python-keycloak.readthedocs.io>`_.
  41. Contributors
  42. ==================
  43. * `Agriness Team <http://www.agriness.com/pt/>`_
  44. Usage
  45. =====
  46. Main methods::
  47. from keycloak import Keycloak
  48. # Configure client
  49. keycloak = Keycloak(server_url="http://localhost:8080/auth/",
  50. client_id="example_client",
  51. realm_name="example_realm",
  52. client_secret_key="secret")
  53. # Get WellKnow
  54. config_well_know = keycloak.well_know()
  55. # Get Token
  56. token = keycloak.token("user", "password")
  57. # Get Userinfo
  58. userinfo = keycloak.userinfo(token['access_token'])
  59. # Logout
  60. keycloak.logout(token['refresh_token'])
  61. # Get Certs
  62. certs = keycloak.certs()
  63. # Get RPT (Entitlement)
  64. token = keycloak.token("user", "password")
  65. rpt = keycloak.entitlement(token['access_token'], "resource_id")
  66. # Instropect RPT
  67. token_rpt_info = keycloak.instropect(keycloak.instropect(token['access_token'], rpt=rpt['rpt'],
  68. token_type_hint="requesting_party_token"))
  69. # Introspect Token
  70. token_info = keycloak.introspect(token['access_token']))
  71. # Decode Token
  72. KEYCLOAK_PUBLIC_KEY = "secret"
  73. options = {"verify_signature": True, "verify_aud": True, "exp": True}
  74. token_info = keycloak.decode_token(token['access_token'], key=KEYCLOAK_PUBLIC_KEY, options=options)
  75. # Get permissions by token
  76. token = keycloak.token("user", "password")
  77. keycloak.load_authorization_config("example-authz-config.json")
  78. policies = keycloak.get_policies(token['access_token'], method_token_info='decode', key=KEYCLOAK_PUBLIC_KEY)
  79. permissions = keycloak.get_permissions(token['access_token'], method_token_info='introspect')