Skip to content

Commit bce67e6

Browse files
📖 🐈 Switch to Sphinx for Documentation (HarryMWinters#8)
- Switch to Sphinx for documentation. - Update Readme to point to ReadTheDocs and PyPI - Remove unused publish docs task
1 parent 8b651f2 commit bce67e6

File tree

7 files changed

+90
-56
lines changed

7 files changed

+90
-56
lines changed

.github/workflows/publish_docs.yaml

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

README.md

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,31 @@
22

33
# FastAPI OIDC
44

5-
![Tests](https://github.com/HarryMWinters/fastapi-oidc/workflows/Test/badge.svg)
5+
<p align="center">
6+
<a href="https://github.com/HarryMWinters/fastapi-oidc/actions?query=workflow%3ATest"
7+
target="_blank">
8+
<img src="https://github.com/HarryMWinters/fastapi-oidc/workflows/Test/badge.svg"
9+
alt="Test">
10+
</a>
11+
<a href='https://fastapi-oidc.readthedocs.io/en/latest/?badge=latest'>
12+
<img src='https://readthedocs.org/projects/fastapi-oidc/badge/?version=latest' alt='Documentation Status' />
13+
</a>
14+
<a href="https://pypi.org/project/fastapi-oidc"
15+
target="_blank">
16+
<img src="https://img.shields.io/pypi/v/fastapi-oidc?color=%2334D058&label=pypi%20package"
17+
alt="Package version">
18+
</a>
19+
</p>
20+
21+
---
622

723
:warning: **See [this issue](https://github.com/HarryMWinters/fastapi-oidc/issues/1) for simple role-your-own example of checking OIDC tokens.**
824

925
Verify and decrypt 3rd party OIDC ID tokens to protect your [fastapi](https://github.com/tiangolo/fastapi) endpoints.
1026

11-
Docs: [gh-Pages](https://harrymwinters.github.io/fastapi-oidc/)
27+
**Documentation:** [ReadTheDocs](https://fastapi-oidc.readthedocs.io/en/latest/)
1228

13-
Source code: [Github](https://github.com/HarryMWinters/fastapi-oidc)
29+
**Source code:** [Github](https://github.com/HarryMWinters/fastapi-oidc)
1430

1531
### Installation
1632

docs/conf.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@
3030
# Add any Sphinx extension module names here, as strings. They can be
3131
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
3232
# ones.
33-
extensions = [
34-
"sphinx.ext.autodoc",
35-
]
33+
extensions = ["sphinx.ext.autodoc", "sphinx.ext.napoleon"]
3634

3735
# Add any paths that contain templates here, relative to this directory.
3836
templates_path = ["_templates"]

docs/index.rst

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ Installation
2424
.. code-block:: bash
2525
2626
pip install fastapi-oidc
27+
28+
Or, if you you're feeling hip...
29+
30+
.. code-block:: bash
31+
32+
poetry add fastapi-oidc
2733
2834
Example
2935
-------
@@ -55,12 +61,16 @@ Basic configuration for verifying OIDC tokens.
5561
return {"Hello": "World", "user_email": id_token.email}
5662
5763
58-
API References
59-
--------------
64+
API Reference
65+
=============
6066

61-
.. automodule:: fastapi_oidc
67+
Auth
68+
----
69+
70+
.. automodule:: fastapi_oidc.auth
6271
:members:
6372

73+
6474
Discovery
6575
---------
6676

fastapi_oidc/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +0,0 @@
1-
"""Place holder for working with 3rd party OIDC ID tokens in fastapi """

fastapi_oidc/auth.py

Lines changed: 56 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,23 @@
11
# -*- coding: utf-8 -*-
22
"""
33
Module for validating OIDC ID Tokens. Configured via config.py
4-
#. Usage
4+
5+
Usage
6+
=====
7+
58
.. code-block:: python3
6-
from app.auth import authenticate_user
9+
10+
# This assumes you've already configured get_auth in your_app.py
11+
from you_app.auth import authenticate_user
12+
713
@app.get("/auth")
814
def test_auth(authenticated_user: AuthenticatedUser = Depends(authenticate_user)):
915
name = authenticated_user.preferred_username
1016
return f"Hello {name}"
1117
"""
1218

19+
from typing import Callable
20+
1321
from fastapi import Depends
1422
from fastapi import HTTPException
1523
from fastapi.security import OpenIdConnect
@@ -28,8 +36,28 @@ def get_auth(
2836
base_authorization_server_uri: str,
2937
issuer: str,
3038
signature_cache_ttl: int,
31-
):
39+
) -> Callable[[str], IDToken]:
40+
"""Take configurations and return the authenticate_user function.
41+
42+
This function should only be invoked once at the begging of your
43+
server code. The function it returns should be used to check user credentials.
44+
45+
Args:
46+
client_id (str): This string is provided when you register with your resource server.
47+
base_authorization_server_uri(URL): Everything before /.wellknow in your auth server URL.
48+
I.E. https://dev-123456.okta.com
49+
issuer (URL): Same as base_authorization. This is used to generating OpenAPI3.0 docs which
50+
is broken (in OpenAPI/FastAPI) right now.
51+
signature_cache_ttl (int): How many seconds your app should cache the authorization
52+
server's public signatures.
3253
54+
55+
Returns:
56+
func: authenticate_user(auth_header: str)
57+
58+
Raises:
59+
Nothing intentional
60+
"""
3361
# As far as I can tell this does two things.
3462
# 1. Extracts and returns the Authorization header.
3563
# 2. Integrates with the OpenAPI3.0 doc generation in FastAPI.
@@ -41,19 +69,17 @@ def get_auth(
4169

4270
discover = discovery.configure(cache_ttl=signature_cache_ttl)
4371

44-
def authenticate_user(
45-
auth_header: str = Depends(oauth2_scheme),
46-
client_id: str = client_id,
47-
base_authorization_server_uri: str = base_authorization_server_uri,
48-
issuer: str = issuer,
49-
signature_cache_ttl: int = signature_cache_ttl,
50-
) -> IDToken:
72+
def authenticate_user(auth_header: str = Depends(oauth2_scheme)) -> IDToken:
5173
"""Validate and parse OIDC ID token against issuer in config.
5274
Note this function caches the signatures and algorithms of the issuing server
5375
for signature_cache_ttl seconds.
5476
55-
return:
56-
IDToken:
77+
Args:
78+
auth_header (str): Base64 encoded OIDC Token. This is invoked behind the scenes
79+
by Depends.
80+
81+
Return:
82+
IDToken (types.IDToken):
5783
5884
raises:
5985
HTTPException(status_code=401, detail=f"Unauthorized: {err}")
@@ -80,3 +106,21 @@ def authenticate_user(
80106
raise HTTPException(status_code=401, detail=f"Unauthorized: {err}")
81107

82108
return authenticate_user
109+
110+
111+
# This is a dummy method for sphinx docs. DO NOT User.
112+
# TODO Find a way to doc higher order functions w/ sphinx.
113+
def authenticate_user(auth_header: str) -> IDToken:
114+
"""
115+
Validate and parse OIDC ID token against issuer in config.
116+
Note this function caches the signatures and algorithms of the issuing server
117+
for signature_cache_ttl seconds.
118+
119+
Args:
120+
auth_header (str): Base64 encoded OIDC Token. This is invoked behind the scenes
121+
by Depends.
122+
123+
Return:
124+
IDToken (types.IDToken):
125+
"""
126+
pass

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ license = "MIT"
77
readme = "README.md"
88
homepage = "https://github.com/HarryMWinters/fastapi-oidc"
99
repository = "https://github.com/HarryMWinters/fastapi-oidc"
10-
documentation = "https://github.com/HarryMWinters/fastapi-oidc"
10+
documentation = "https://fastapi-oidc.readthedocs.io/en/latest/"
1111

1212
[tool.poetry.dependencies]
1313
python = "^3.8"

0 commit comments

Comments
 (0)