Skip to content

Commit

Permalink
chore: rename library
Browse files Browse the repository at this point in the history
  • Loading branch information
samedii committed Sep 15, 2021
1 parent 630978c commit 8e4df16
Show file tree
Hide file tree
Showing 15 changed files with 72 additions and 59 deletions.
51 changes: 30 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,57 +1,66 @@
# FastAPI OIDC
# FastAPI Third Party Auth

<p align="left">
<a href="https://github.com/HarryMWinters/fastapi-oidc/actions?query=workflow%3ATest"
<a href="https://github.com/aiwizo/fastapi-third-party-auth/actions?query=workflow%3ATest"
target="_blank">
<img src="https://github.com/HarryMWinters/fastapi-oidc/workflows/Test/badge.svg"
<img src="https://github.com/aiwizo/fastapi-third-party-auth/workflows/Test/badge.svg"
alt="Test">
</a>
<a href='https://fastapi-oidc.readthedocs.io/en/latest/?badge=latest'>
<img src='https://readthedocs.org/projects/fastapi-oidc/badge/?version=latest' alt='Documentation Status' />
<a href='https://fastapi-third-party-auth.readthedocs.io/en/latest/?badge=latest'>
<img src='https://readthedocs.org/projects/fastapi-third-party-auth/badge/?version=latest' alt='Documentation Status' />
</a>
<a href="https://pypi.org/project/fastapi-oidc"
<a href="https://pypi.org/project/fastapi-third-party-auth"
target="_blank">
<img src="https://img.shields.io/pypi/v/fastapi-oidc?color=%2334D058&label=pypi%20package"
<img src="https://img.shields.io/pypi/v/fastapi-third-party-auth?color=%2334D058&label=pypi%20package"
alt="Package version">
</a>
</p>

---

**Documentation**: <a href="https://fastapi-oidc.readthedocs.io/" target="_blank">https://fastapi-oidc.readthedocs.io/</a>
**Documentation**: <a href="https://fastapi-third-party-auth.readthedocs.io/" target="_blank">https://fastapi-third-party-auth.readthedocs.io/</a>

**Source Code**: <a href="https://github.com/HarryMWinters/fastapi-oidc" target="_blank">https://github.com/HarryMWinters/fastapi-oidc</a>
**Source Code**: <a href="https://github.com/aiwizo/fastapi-third-party-auth" target="_blank">https://github.com/aiwizo/fastapi-third-party-auth</a>

---

Verify and decrypt 3rd party OpenID Connect tokens to protect your
[FastAPI](https://github.com/tiangolo/fastapi) endpoints.
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 authenticators such as:
Easily used with authentication services such as:
- [Keycloak](https://www.keycloak.org/) (open source)
- [SuperTokens](https://supertokens.io/) (open source)
- [Auth0](https://auth0.com/)
- [Okta](https://www.okta.com/products/authentication/)

FastAPI's generated interactive documentation supports the grant flows
`authorization_code`, `implicit`, `password` and `client_credentials`.
FastAPI's generated interactive documentation supports the grant flows:
```python3
GrantType.AUTHORIZATION_CODE
GrantType.IMPLICIT
GrantType.PASSWORD
GrantType.CLIENT_CREDENTIALS
```

![example documentation](example-docs.png)

## Installation

```
poetry add fastapi-oidc
poetry add fastapi-third-party-auth
```

Or, for the old-timers:

```
pip install fastapi-oidc
pip install fastapi-third-party-auth
```

## Usage

See this example for how to use `docker-compose` to set up authentication with
fastapi-oidc + keycloak.
See [this example](tree/master/example) for how to use
`docker-compose` to set up authentication with `fastapi-third-party-auth` +
[Keycloak](https://www.keycloak.org/).

### Standard usage

Expand All @@ -61,9 +70,9 @@ from fastapi import FastAPI
from fastapi import Security
from fastapi import status

from fastapi_oidc import Auth
from fastapi_oidc import GrantType
from fastapi_oidc import KeycloakIDToken
from fastapi_third_party_auth import Auth
from fastapi_third_party_auth import GrantType
from fastapi_third_party_auth import KeycloakIDToken

auth = Auth(
openid_connect_url="http://localhost:8080/auth/realms/my-realm/.well-known/openid-configuration",
Expand Down
2 changes: 1 addition & 1 deletion Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ tasks:
cmds:
- poetry build
sources:
- fastapi_oidc/**
- fastapi_third_party_auth/**
- poetry.lock
- pyproject.toml
generates:
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

# -- Project information -----------------------------------------------------

project = "fastapi-oidc"
project = "fastapi-third-party-auth"
copyright = "2020, Harry M. Winters"
author = "Harry M. Winters"

Expand Down
18 changes: 9 additions & 9 deletions docs/index.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Welcome to fastapi-oidc's documentation!
Welcome to fastapi-third-party-auth's documentation!
========================================

Verify and decrypt 3rd party OpenID Connect tokens to protect your
Expand Down Expand Up @@ -31,13 +31,13 @@ Installation

.. code-block:: bash
poetry add fastapi-oidc
poetry add fastapi-third-party-auth
Or, for the old-timers:

.. code-block:: bash
pip install fastapi-oidc
pip install fastapi-third-party-auth
Example
-------
Expand All @@ -51,9 +51,9 @@ Basic configuration for verifying OIDC tokens.
from fastapi import Security
from fastapi import status
from fastapi_oidc import Auth
from fastapi_oidc import GrantType
from fastapi_oidc import KeycloakIDToken
from fastapi_third_party_auth import Auth
from fastapi_third_party_auth import GrantType
from fastapi_third_party_auth import KeycloakIDToken
auth = Auth(
openid_connect_url="http://localhost:8080/auth/realms/my-realm/.well-known/openid-configuration",
Expand All @@ -80,16 +80,16 @@ API Reference

Auth
----
.. automodule:: fastapi_oidc.auth
.. automodule:: fastapi_third_party_auth.auth
:members:

Grant Types
-----------
.. automodule:: fastapi_oidc.grant_types
.. automodule:: fastapi_third_party_auth.grant_types
:members:
:undoc-members:

IDToken Types
-------------
.. automodule:: fastapi_oidc.idtoken_types
.. automodule:: fastapi_third_party_auth.idtoken_types
:members:
Binary file added example-docs.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 3 additions & 5 deletions example/app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
from fastapi.middleware.cors import CORSMiddleware
from starlette.responses import RedirectResponse

from fastapi_oidc import Auth
from fastapi_oidc import KeycloakIDToken
from fastapi_third_party_auth import Auth
from fastapi_third_party_auth import KeycloakIDToken

auth = Auth(
openid_connect_url="http://localhost:8080/auth/realms/my-realm/.well-known/openid-configuration",
Expand Down Expand Up @@ -56,6 +56,4 @@ def mixed(id_token: Optional[KeycloakIDToken] = Security(auth.optional)):


if __name__ == "__main__":
uvicorn.run(
"example.main:cors", host="0.0.0.0", port=8000, loop="asyncio", reload=True
)
uvicorn.run("app.main:cors", host="0.0.0.0", port=8000, loop="asyncio", reload=True)
5 changes: 0 additions & 5 deletions fastapi_oidc/__init__.py

This file was deleted.

5 changes: 5 additions & 0 deletions fastapi_third_party_auth/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from fastapi_third_party_auth.auth import Auth # noqa
from fastapi_third_party_auth.grant_types import GrantType # noqa
from fastapi_third_party_auth.idtoken_types import IDToken # noqa
from fastapi_third_party_auth.idtoken_types import KeycloakIDToken # noqa
from fastapi_third_party_auth.idtoken_types import OktaIDToken # noqa
6 changes: 3 additions & 3 deletions fastapi_oidc/auth.py → fastapi_third_party_auth/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ def test_auth(authenticated_user: IDToken = Depends(auth.required)):
from jose import jwt
from jose.exceptions import JWTClaimsError

from fastapi_oidc import discovery
from fastapi_oidc.grant_types import GrantType
from fastapi_oidc.idtoken_types import IDToken
from fastapi_third_party_auth import discovery
from fastapi_third_party_auth.grant_types import GrantType
from fastapi_third_party_auth.idtoken_types import IDToken


class Auth(OAuth2):
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
14 changes: 7 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
[tool.poetry]
name = "fastapi-oidc"
name = "fastapi-third-party-auth"
version = "0.0.0"
description = "A simple library for parsing and verifying externally issued OIDC ID tokens in fastapi."
authors = ["HarryMWinters <[email protected]>"]
description = "Simple library for using a third party authentication service like Keycloak or Auth0 with FastAPI"
authors = ["HarryMWinters <[email protected]>", "Richard Löwenström <[email protected]>"]
license = "MIT"
readme = "README.md"
homepage = "https://github.com/HarryMWinters/fastapi-oidc"
repository = "https://github.com/HarryMWinters/fastapi-oidc"
documentation = "https://fastapi-oidc.readthedocs.io/en/latest/"
homepage = "https://github.com/aiwizo/fastapi-third-party-auth"
repository = "https://github.com/aiwizo/fastapi-third-party-auth"
documentation = "https://fastapi-third-party-auth.readthedocs.io/en/latest/"

[tool.poetry.dependencies]
python = "^3.8"
Expand Down Expand Up @@ -37,4 +37,4 @@ build-backend = "poetry.masonry.api"
profile = "black"
force_single_line = "True"
known_first_party = []
known_third_party = ["cachetools", "cryptography", "fastapi", "jose", "jwt", "pydantic", "pytest", "requests", "starlette", "uvicorn"]
known_third_party = ["cachetools", "cryptography", "fastapi", "jose", "jwt", "pydantic", "pytest", "requests", "starlette", "uvicorn"]
18 changes: 12 additions & 6 deletions tests/test_auth.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from fastapi.security import HTTPAuthorizationCredentials
from fastapi.security import SecurityScopes

import fastapi_oidc
from fastapi_oidc import Auth
from fastapi_oidc.idtoken_types import IDToken
import fastapi_third_party_auth
from fastapi_third_party_auth import Auth
from fastapi_third_party_auth.idtoken_types import IDToken


def test__authenticate_user(
Expand All @@ -13,7 +13,9 @@ def test__authenticate_user(
config_w_aud,
test_email,
):
monkeypatch.setattr(fastapi_oidc.auth.discovery, "configure", mock_discovery)
monkeypatch.setattr(
fastapi_third_party_auth.auth.discovery, "configure", mock_discovery
)

token = token_with_audience

Expand All @@ -37,7 +39,9 @@ def test__authenticate_user_no_aud(
test_email,
):

monkeypatch.setattr(fastapi_oidc.auth.discovery, "configure", mock_discovery)
monkeypatch.setattr(
fastapi_third_party_auth.auth.discovery, "configure", mock_discovery
)

token = token_without_audience

Expand All @@ -59,7 +63,9 @@ def test__authenticate_user_returns_custom_tokens(
class CustomToken(IDToken):
custom_field: str = "OnlySlightlyBent"

monkeypatch.setattr(fastapi_oidc.auth.discovery, "configure", mock_discovery)
monkeypatch.setattr(
fastapi_third_party_auth.auth.discovery, "configure", mock_discovery
)

token = token_without_audience

Expand Down
2 changes: 1 addition & 1 deletion tests/test_types.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pydantic
import pytest

from fastapi_oidc import idtoken_types
from fastapi_third_party_auth import idtoken_types


def test_IDToken_raises_with_bad_field_types():
Expand Down

0 comments on commit 8e4df16

Please sign in to comment.