Skip to content

Commit

Permalink
Improved code climate
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Slump committed Mar 3, 2018
1 parent d177d53 commit 1a70d85
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 25 deletions.
18 changes: 18 additions & 0 deletions src/keycloak/mixins.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from keycloak.well_known import KeycloakWellKnown


class WellKnownMixin(object):

def get_path_well_known(self):
raise NotImplementedError()

@property
def well_known(self):
if self._well_known is None:
self._well_known = KeycloakWellKnown(
realm=self._realm,
path=self._realm.client.get_full_url(
self.get_path_well_known().format(self._realm.realm_name)
)
)
return self._well_known
18 changes: 5 additions & 13 deletions src/keycloak/openid_connect.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
from collections import OrderedDict

from keycloak.mixins import WellKnownMixin

try:
from urllib.parse import urlencode
except ImportError:
from urllib import urlencode

from jose import jwt

from keycloak.well_known import KeycloakWellKnown

PATH_WELL_KNOWN = "auth/realms/{}/.well-known/openid-configuration"


class KeycloakOpenidConnect(object):
class KeycloakOpenidConnect(WellKnownMixin):

_well_known = None
_client_id = None
Expand All @@ -29,16 +29,8 @@ def __init__(self, realm, client_id, client_secret):
self._client_secret = client_secret
self._realm = realm

@property
def well_known(self):
if self._well_known is None:
self._well_known = KeycloakWellKnown(
realm=self._realm,
path=self._realm.client.get_full_url(
PATH_WELL_KNOWN.format(self._realm.realm_name)
)
)
return self._well_known
def get_path_well_known(self):
return PATH_WELL_KNOWN

def get_url(self, name):
return self.well_known[name]
Expand Down
16 changes: 4 additions & 12 deletions src/keycloak/uma.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,20 @@
import json

from keycloak.well_known import KeycloakWellKnown
from keycloak.mixins import WellKnownMixin

PATH_WELL_KNOWN = "auth/realms/{}/.well-known/uma-configuration"


class KeycloakUMA(object):
class KeycloakUMA(WellKnownMixin, object):

_realm = None
_well_known = None

def __init__(self, realm):
self._realm = realm

@property
def well_known(self):
if self._well_known is None:
self._well_known = KeycloakWellKnown(
realm=self._realm,
path=self._realm.client.get_full_url(
PATH_WELL_KNOWN.format(self._realm.realm_name)
)
)
return self._well_known
def get_path_well_known(self):
return PATH_WELL_KNOWN

def resource_set_create(self, token, name, uri=None, type=None,
scopes=None, icon_url=None):
Expand Down

0 comments on commit 1a70d85

Please sign in to comment.