Skip to content

Commit

Permalink
fix: cache lock for threading support
Browse files Browse the repository at this point in the history
  • Loading branch information
samedii committed Oct 6, 2022
1 parent 4ae8980 commit 039ee19
Show file tree
Hide file tree
Showing 8 changed files with 623 additions and 788 deletions.
6 changes: 0 additions & 6 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ jobs:
with:
python-version: ${{ matrix.python-version }}

- name: Install Task
uses: arduino/setup-task@v1

- name: Install Poetry
uses: snok/install-poetry@v1
with:
Expand All @@ -38,9 +35,6 @@ jobs:
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: poetry install --no-interaction --no-root

- name: Run CI
run: task ci

- name: Build wheels
run: |
poetry version $(git tag --points-at HEAD)
Expand Down
6 changes: 0 additions & 6 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,6 @@ jobs:
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}

- name: Install Task
uses: arduino/setup-task@v1

- name: Install Poetry
uses: snok/install-poetry@v1

- name: Run CI
run: task ci
44 changes: 0 additions & 44 deletions .pre-commit-config.yaml

This file was deleted.

6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,19 @@

---

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

Easily used with authentication services such as:

- [Keycloak](https://www.keycloak.org/) (open source)
- [SuperTokens](https://supertokens.io/) (open source)
- [SuperTokens](https://supertokens.com/) (open source)
- [Auth0](https://auth0.com/)
- [Okta](https://www.okta.com/products/authentication/)

FastAPI's generated interactive documentation supports the grant flows:

```python3
GrantType.AUTHORIZATION_CODE
GrantType.IMPLICIT
Expand Down
88 changes: 0 additions & 88 deletions Taskfile.yml

This file was deleted.

6 changes: 3 additions & 3 deletions fastapi_third_party_auth/discovery.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from typing import Dict

import requests
from cachetools import TTLCache
from cachetools import cached
from threading import Lock


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

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

0 comments on commit 039ee19

Please sign in to comment.