Skip to content

Commit

Permalink
Fix jwk pool key handling (NabuCasa#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
pvizeli authored Mar 9, 2020
1 parent 083525b commit 2136566
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ WORKDIR /workspaces

# Install Python dependencies from requirements.txt if it exists
COPY requirements_test.txt .
RUN pip3 install -r requirement_test.txt \
RUN pip3 install -r requirements_test.txt \
&& pip3 install tox \
&& rm -f requirements_test.txt

Expand Down
19 changes: 9 additions & 10 deletions pycognito/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,22 +197,21 @@ def __init__(
self.client = boto3.client("cognito-idp", **boto3_client_kwargs)

def get_keys(self):

try:
if self.pool_jwk:
return self.pool_jwk
except AttributeError:
# Check for the dictionary in environment variables.
pool_jwk_env = env("COGNITO_JWKS", {}, var_type="dict")
if len(pool_jwk_env.keys()) > 0:
self.pool_jwk = pool_jwk_env
return self.pool_jwk
# If it is not there use the requests library to get it

# Check for the dictionary in environment variables.
pool_jwk_env = env("COGNITO_JWKS", {}, var_type="dict")
if pool_jwk_env:
self.pool_jwk = pool_jwk_env
# If it is not there use the requests library to get it
else:
self.pool_jwk = requests.get(
"https://cognito-idp.{}.amazonaws.com/{}/.well-known/jwks.json".format(
self.user_pool_region, self.user_pool_id
)
).json()
return self.pool_jwk
return self.pool_jwk

def get_key(self, kid):
keys = self.get_keys().get("keys")
Expand Down

0 comments on commit 2136566

Please sign in to comment.