Skip to content

Commit 039ee19

Browse files
committed
fix: cache lock for threading support
1 parent 4ae8980 commit 039ee19

File tree

8 files changed

+623
-788
lines changed

8 files changed

+623
-788
lines changed

.github/workflows/publish.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@ jobs:
1818
with:
1919
python-version: ${{ matrix.python-version }}
2020

21-
- name: Install Task
22-
uses: arduino/setup-task@v1
23-
2421
- name: Install Poetry
2522
uses: snok/install-poetry@v1
2623
with:
@@ -38,9 +35,6 @@ jobs:
3835
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
3936
run: poetry install --no-interaction --no-root
4037

41-
- name: Run CI
42-
run: task ci
43-
4438
- name: Build wheels
4539
run: |
4640
poetry version $(git tag --points-at HEAD)

.github/workflows/tests.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,6 @@ jobs:
2121
uses: actions/setup-python@v1
2222
with:
2323
python-version: ${{ matrix.python-version }}
24-
25-
- name: Install Task
26-
uses: arduino/setup-task@v1
2724

2825
- name: Install Poetry
2926
uses: snok/install-poetry@v1
30-
31-
- name: Run CI
32-
run: task ci

.pre-commit-config.yaml

Lines changed: 0 additions & 44 deletions
This file was deleted.

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,19 @@
2424

2525
---
2626

27-
Simple library for using a third party authentication service with
27+
Simple library for using a third party authentication service with
2828
[FastAPI](https://github.com/tiangolo/fastapi). Verifies and decrypts 3rd party
2929
OpenID Connect tokens to protect your endpoints.
3030

3131
Easily used with authentication services such as:
32+
3233
- [Keycloak](https://www.keycloak.org/) (open source)
33-
- [SuperTokens](https://supertokens.io/) (open source)
34+
- [SuperTokens](https://supertokens.com/) (open source)
3435
- [Auth0](https://auth0.com/)
3536
- [Okta](https://www.okta.com/products/authentication/)
3637

3738
FastAPI's generated interactive documentation supports the grant flows:
39+
3840
```python3
3941
GrantType.AUTHORIZATION_CODE
4042
GrantType.IMPLICIT

Taskfile.yml

Lines changed: 0 additions & 88 deletions
This file was deleted.

fastapi_third_party_auth/discovery.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
from typing import Dict
2-
32
import requests
43
from cachetools import TTLCache
54
from cachetools import cached
5+
from threading import Lock
66

77

88
def configure(*_, cache_ttl: int):
9-
@cached(TTLCache(1, cache_ttl), key=lambda d: d["jwks_uri"])
9+
@cached(TTLCache(1, cache_ttl), key=lambda d: d["jwks_uri"], lock=Lock())
1010
def get_authentication_server_public_keys(OIDC_spec: Dict):
1111
"""
1212
Retrieve the public keys used by the authentication server
@@ -21,7 +21,7 @@ def get_signing_algos(OIDC_spec: Dict):
2121
algos = OIDC_spec["id_token_signing_alg_values_supported"]
2222
return algos
2323

24-
@cached(TTLCache(1, cache_ttl))
24+
@cached(TTLCache(1, cache_ttl), lock=Lock())
2525
def discover_auth_server(*_, openid_connect_url: str) -> Dict:
2626
r = requests.get(openid_connect_url)
2727
# Raise if the auth server is failing since we can't verify tokens

0 commit comments

Comments
 (0)