Skip to main content

FastAPI-authkit is an extenstion to provide oauth-oidc authentication/authorization and user management for fastapi.

Project description

Logo

FastAPI AuthKit

FastAPI-authkit is an extenstion to provide oauth-oidc authentication/authorization and user management for fastapi.

Features and supported OIDC providers

  • Login/SignUp based on following providers:
  • Google
  • Twitter
  • Github
  • Zoom
  • SSO (OKTA)
  • Facebook (Coming soon...)
  • Microsoft (Coming soon...)
  • Apple (Coming soon...)
  • User management (Coming soon...)

Installation

Install FastAPI AuthKit with pip

  pip install fastapi_authkit

Usage/Examples

import fastapi
from fastapi_authkit import (
    OAuthApp,
    AuthSetting,
    AuthProviders,
)
from fastapi_authkit.utils import jwt

fake_db = {}
SECRET_KEY = "This is a secret key"


class AuthLogic(AuthProviders.IAuthLogic):
    header: dict[str, str] = {"alg": "HS256"}

    async def login(
        self, userinfo: AuthProviders.UserInfoModel
    ) -> AuthProviders.Token | None:
        if userinfo.name in fake_db:
            return AuthProviders.Token(
                jwt.encode(
                    header=self.header,
                    key=SECRET_KEY,
                    payload=userinfo.dict(),
                ).decode()
            )

    async def singup(self, userinfo: AuthProviders.UserInfoModel) -> None:
        global fake_db
        fake_db[userinfo.name] = userinfo


app: fastapi.FastAPI = fastapi.FastAPI()
auth_router: fastapi.APIRouter = fastapi.APIRouter(prefix="/auth")
auth_app: OAuthApp = OAuthApp(app=app, secret_key=SECRET_KEY)
auth_vias: AuthProviders.AuthVia = AuthProviders.AuthVia(
    oapp=auth_app.oauth,
    vias=(
        AuthSetting(
            name="google",
            client_id="{{client-id}}",
            client_secret="{{client-secret}}",
            client_kwargs=dict(scope="openid profile"),
        ).dict(),
        AuthSetting(
            name="github",
            client_id="{{client-id}}",
            client_secret="{{client-secret}}",
            client_kwargs=dict(scope="user:email"),
        ).dict(),
        AuthSetting(
            name="zoom",
            client_id="{{client-id}}",
            client_secret="{{client-secret}}",
            client_kwargs=dict(scope="openid profile"),
        ).dict(),
        AuthSetting(
            name="okta",
            client_id="{{client-id}}",
            client_secret="{{client-secret}}",
            api_base_url="https://dev-ea46b3xduc1q1lb4.us.auth0.com",
            client_kwargs=dict(scope="openid profile"),
        ).dict(),
        AuthSetting(
            name="twitter",
            client_id="{{twitter-client-id}}",
            client_secret="{{twitter-client-secret}}",
            client_kwargs=dict(scope="users.read"),
        ).dict(),
    ),
)
auth_logic: AuthLogic = AuthLogic()
AuthProviders.GoogleAuthenticationMethod(
    router=auth_router,
    oauth_app=auth_app,
    auth_vias=auth_vias,
    auth_logic=auth_logic,
)
AuthProviders.ZoomAuthenticationMethod(
    router=auth_router,
    oauth_app=auth_app,
    auth_vias=auth_vias,
    auth_logic=auth_logic,
)
AuthProviders.GithubAuthenticationMethod(
    router=auth_router,
    oauth_app=auth_app,
    auth_vias=auth_vias,
    auth_logic=auth_logic,
)
AuthProviders.OktaAuthenticationMethod(
    router=auth_router,
    oauth_app=auth_app,
    auth_vias=auth_vias,
    auth_logic=auth_logic,
)
AuthProviders.TwitterAuthenticationMethod(
    router=auth_router,
    oauth_app=auth_app,
    auth_vias=auth_vias,
    auth_logic=auth_logic,
)

Authors

Contributing

Contributions are always welcome!

See contributing.md for ways to get started.

Please adhere to this project's code of conduct.

License

MIT

Support

For support, email papuridalego@gmail.com or join our Telegram Group (Ask us in email).

Feedback

If you have any feedback, please reach out to us at papuridalego@gmail.com

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fastapi-authkit-0.0.2.tar.gz (10.6 kB view details)

Uploaded Source

Built Distribution

fastapi_authkit-0.0.2-py3-none-any.whl (10.7 kB view details)

Uploaded Python 3

File details

Details for the file fastapi-authkit-0.0.2.tar.gz.

File metadata

  • Download URL: fastapi-authkit-0.0.2.tar.gz
  • Upload date:
  • Size: 10.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.2

File hashes

Hashes for fastapi-authkit-0.0.2.tar.gz
Algorithm Hash digest
SHA256 2a9e4b9187cd2c952b44e004230a14b986ca8d4236af8a085aba025f9bfca715
MD5 c34090ee2d97889f80b771ec518175fe
BLAKE2b-256 942a793642df591350c7c1413b580c8aac0aecfdecb585d84f8f13ce1508396f

See more details on using hashes here.

File details

Details for the file fastapi_authkit-0.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for fastapi_authkit-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 6b19bd66021807b0d0f3935fb5dbc6969be31ae3f37565d9f2cccf138a51144b
MD5 784c5cb36ff5717d72296e9f28a0c86c
BLAKE2b-256 a332205a29d39c9aa71f94ab032b2155798e1b644051ceed4e991a2090e320fb

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page