in source/token-authorizer/chalice/app.py [0:0]
def get_public_key():
"""
This function is responsible for retrieving the
public JWK from the closest location
"""
# Bandit B108: /tmp directory is ephemeral as this is ran on Lambda
local_key_file = "/tmp/jwks.json" # nosec
key = {}
if os.path.isfile(local_key_file):
# retrieve from the local file
with open(local_key_file, 'rt', encoding='utf-8') as cache_file:
key = json.loads(cache_file.read())
else:
# retrieve from the core API
api_endpoint = f'{PUBLIC_API_ENDPOINT}/public_key?event_id={WAITING_ROOM_EVENT_ID}'
try:
response = requests.get(api_endpoint)
if response.status_code == 200:
with open(local_key_file, 'wt', encoding='utf-8') as cache_file:
cache_file.write(response.text)
key = json.loads(response.text)
except (OSError, RuntimeError):
print_exception()
return key