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.

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