Skip to main content

OpenID Connect for FastAPI

prokie-fastapi-oidc-auth is an extension to FastAPI that allows you to add OpenID Connect based authentication for your endpoints within minutes.

Installation

pip install prokie-fastapi-oidc-auth

Keycloak settings

Admin

admin_username = "admin"
admin_password = "admin"
host = "http://localhost:8080"

Realm

realm = "myrealm"

Client

Set the Access Type to confidential and Standard Flow Enabled to ON. Make sure that Valid Redirect URIs contain the URI of your app or * if you want to allow all URIs. Make sure Client Protocol is set to openid-connect.

client = "myclient"
secret = "xZEIb4wGoWseNumHJ4Vb7pYvdX3SIQeg"

User

user_username = "myuser"
user_password = "myuser"

How to use

See test.py for a complete example.

Testing

To start a Keycloak instance for testing, run the following command:

docker run -d -p 8080:8080 \
            -e KEYCLOAK_USER=admin \
            -e KEYCLOAK_PASSWORD=admin \
            -e KEYCLOAK_IMPORT=/opt/jboss/keycloak/imports/realm-export-16.1.1.json \
            -v $(pwd)/realm-export-16.1.1.json:/opt/jboss/keycloak/imports/realm-export-16.1.1.json \
            --name keycloak \
            jboss/keycloak:16.1.1
docker run -d -p 8080:8080 `
            -e KEYCLOAK_USER=admin `
            -e KEYCLOAK_PASSWORD=admin `
            -e KEYCLOAK_IMPORT=/opt/jboss/keycloak/imports/realm-export-16.1.1.json `
            -v ${PWD}\realm-export-16.1.1.json:/opt/jboss/keycloak/imports/realm-export-16.1.1.json `
            --name keycloak `
            jboss/keycloak:16.1.1

To export the realm configuration, run the following command:

docker exec -it keycloak /opt/jboss/keycloak/bin/standalone.sh \
-Djboss.socket.binding.port-offset=100 -Dkeycloak.migration.action=export \
-Dkeycloak.migration.provider=singleFile \
-Dkeycloak.migration.realmName=myrealm \
-Dkeycloak.migration.usersExportStrategy=REALM_FILE \
-Dkeycloak.migration.file=/tmp/realm-export-16.1.1.json
docker exec -it keycloak /opt/jboss/keycloak/bin/standalone.sh `
  -Djboss.socket.binding.port-offset=100 `
  -Dkeycloak.migration.action=export `
  -Dkeycloak.migration.provider=singleFile `
  -Dkeycloak.migration.realmName=myrealm `
  -Dkeycloak.migration.usersExportStrategy=REALM_FILE `
  -Dkeycloak.migration.file=/tmp/realm-export-16.1.1.json

Metadata

Release files for prokie-fastapi-oidc-auth 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for prokie-fastapi-oidc-auth 0.2.0
File Size Uploaded Provenance Actions
prokie-fastapi-oidc-auth-0.2.0.tar.gz 47.5 kB Without provenance Details for prokie-fastapi-oidc-auth-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for prokie-fastapi-oidc-auth 0.2.0
File Interpreter ABI Platform Actions
prokie_fastapi_oidc_auth-0.2.0-py3-none-any.whl Python 3 none any Details for prokie_fastapi_oidc_auth-0.2.0-py3-none-any.whl

Total release size: 64.7 kB

Release files / prokie-fastapi-oidc-auth-0.2.0.tar.gz

Download URL prokie-fastapi-oidc-auth-0.2.0.tar.gz
Size 47.5 kB
Tags Source
SHA-256 checksum
How to use checksums
621f08a7da0bdca0342883e9bf4c06032606e32233d13fb0557b867a59fd042c
BLAKE2b-256 checksum
How to use checksums
75aa50dab1d21c9a2eaed71410222457fb5a5611ef59b70bf0ded4ef3a564a65
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.18

Release files / prokie_fastapi_oidc_auth-0.2.0-py3-none-any.whl

Download URL prokie_fastapi_oidc_auth-0.2.0-py3-none-any.whl
Size 17.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bbe28d083b2c2b820865fd5ba6f172c9a5b6ab4eb32e59938fb5fdeb60250714
BLAKE2b-256 checksum
How to use checksums
1499b8ebba305fac66056a26d098c14873888358a4bc99d6f10db23b6175bc73
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.18

Security for prokie-fastapi-oidc-auth 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page