Browse Source

Merge branch 'release/0.7.0'

pull/12/head
Marcos Pereira 7 years ago
parent
commit
1ec6df0dcf
  1. 1
      README.md
  2. 4
      docs/source/conf.py
  3. 1
      docs/source/index.rst
  4. 34
      keycloak/__init__.py
  5. 2
      setup.py

1
README.md

@ -86,6 +86,7 @@ token_info = keycloak.decode_token(token['access_token'], key=KEYCLOAK_PUBLIC_KE
# Get permissions by token
token = keycloak.token("user", "password")
keycloak.load_authorization_config("example-authz-config.json")
policies = keycloak.get_policies(token['access_token'])
permissions = keycloak.get_permissions(token['access_token'])
```

4
docs/source/conf.py

@ -60,9 +60,9 @@ author = 'Marcos Pereira'
# built documents.
#
# The short X.Y version.
version = '0.6.5'
version = '0.7.0'
# The full version, including alpha/beta/rc tags.
release = '0.6.5'
release = '0.7.0'
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.

1
docs/source/index.rst

@ -116,5 +116,6 @@ Main methods::
# Get permissions by token
token = keycloak.token("user", "password")
keycloak.load_authorization_config("example-authz-config.json")
policies = keycloak.get_policies(token['access_token'])
permissions = keycloak.get_permissions(token['access_token'])

34
keycloak/__init__.py

@ -271,6 +271,40 @@ class Keycloak:
self.authorization.load_config(authorization_json)
authorization_file.close()
def get_policies(self, token):
"""
Get policies by user token
:param token: user token
:return: policies list
"""
if not self.authorization.policies:
raise KeycloakAuthorizationConfigError(
"Keycloak settings not found. Load Authorization Keycloak settings."
)
token_info = self.instropect(token)
if not token_info['active']:
raise KeycloakInvalidTokenError(
"Token expired or invalid."
)
user_resources = token_info['resource_access'].get(self.client_id)
if not user_resources:
return None
policies = []
for policy_name, policy in self.authorization.policies.items():
for role in user_resources['roles']:
if self._build_name_role(role) in policy.roles:
policies.append(policy)
return list(set(policies))
def get_permissions(self, token):
"""
Get permission by user token

2
setup.py

@ -4,7 +4,7 @@ from setuptools import setup
setup(
name='python-keycloak',
version='0.6.5',
version='0.7.0',
url='https://github.com/marcospereirampj/python-keycloak',
license='GNU General Public License - V3',
author='Marcos Pereira',

Loading…
Cancel
Save