OIDC auth in fastapi using a decorator
Project description
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.json \
-v $(pwd)/realm-export.json:/opt/jboss/keycloak/imports/realm-export.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.json
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file prokie-fastapi-oidc-auth-0.1.0.tar.gz
.
File metadata
- Download URL: prokie-fastapi-oidc-auth-0.1.0.tar.gz
- Upload date:
- Size: 36.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6dbbb6d1e54ebf2d2b08effb1bf142dceaf99be876a6aa16d23a0a3a048a66b4 |
|
MD5 | 3dec62838329456be34d194ed01d00b2 |
|
BLAKE2b-256 | c7937e0e364b9dc2b998b100130db286dc27e7a0051d5902b59eed34be276a40 |
File details
Details for the file prokie_fastapi_oidc_auth-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: prokie_fastapi_oidc_auth-0.1.0-py3-none-any.whl
- Upload date:
- Size: 17.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 25ba33cdbb72771377aa280a63cb8d40a6c9efba82016726d17239ca5a42eb99 |
|
MD5 | d20c60c059662656f6b01f115518a404 |
|
BLAKE2b-256 | 8476ad7b7cf0c4a883b05c8853e63e656e4b9f6a6dfe2b7795f1ba2048b3f194 |