Skip to content

Commit 2136566

Browse files
authored
Fix jwk pool key handling (#9)
1 parent 083525b commit 2136566

2 files changed

Lines changed: 10 additions & 11 deletions

File tree

.devcontainer/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ WORKDIR /workspaces
44

55
# Install Python dependencies from requirements.txt if it exists
66
COPY requirements_test.txt .
7-
RUN pip3 install -r requirement_test.txt \
7+
RUN pip3 install -r requirements_test.txt \
88
&& pip3 install tox \
99
&& rm -f requirements_test.txt
1010

pycognito/__init__.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -197,22 +197,21 @@ def __init__(
197197
self.client = boto3.client("cognito-idp", **boto3_client_kwargs)
198198

199199
def get_keys(self):
200-
201-
try:
200+
if self.pool_jwk:
202201
return self.pool_jwk
203-
except AttributeError:
204-
# Check for the dictionary in environment variables.
205-
pool_jwk_env = env("COGNITO_JWKS", {}, var_type="dict")
206-
if len(pool_jwk_env.keys()) > 0:
207-
self.pool_jwk = pool_jwk_env
208-
return self.pool_jwk
209-
# If it is not there use the requests library to get it
202+
203+
# Check for the dictionary in environment variables.
204+
pool_jwk_env = env("COGNITO_JWKS", {}, var_type="dict")
205+
if pool_jwk_env:
206+
self.pool_jwk = pool_jwk_env
207+
# If it is not there use the requests library to get it
208+
else:
210209
self.pool_jwk = requests.get(
211210
"https://cognito-idp.{}.amazonaws.com/{}/.well-known/jwks.json".format(
212211
self.user_pool_region, self.user_pool_id
213212
)
214213
).json()
215-
return self.pool_jwk
214+
return self.pool_jwk
216215

217216
def get_key(self, kid):
218217
keys = self.get_keys().get("keys")

0 commit comments

Comments
 (0)