Metadata-Version: 2.4
Name: litestar-sso
Version: 0.20.0
Summary: litestar plugin to enable SSO to most common providers (such as Facebook login, Google login and login via Microsoft Office 365 Account)
License: MIT
License-File: LICENSE.md
Keywords: litestar,sso,oauth,google,facebook,apple,github
Author: Tomas Votava
Author-email: info@tomasvotava.eu
Requires-Python: >=3.10,<4.0
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Requires-Dist: httpx (>=0.23.0)
Requires-Dist: litestar (>=2.12.1,<3.0.0)
Requires-Dist: oauthlib (>=3.1.0)
Requires-Dist: pydantic[email] (>=1.8.0)
Requires-Dist: pyjwt (>=2.0.0)
Project-URL: Documentation, https://tomasvotava.github.io/litestar-sso/
Project-URL: Homepage, https://tomasvotava.github.io/litestar-sso/
Project-URL: Repository, https://github.com/ccrvlh/litestar-sso
Description-Content-Type: text/markdown

# Litestar SSO

![Supported Python Versions](https://img.shields.io/pypi/pyversions/litestar-sso)
[![Test coverage](https://codecov.io/gh/ccrvlh/litestar-sso/graph/badge.svg?token=SIFCTVSSOS)](https://codecov.io/gh/ccrvlh/litestar-sso)
![Tests Workflow Status](https://img.shields.io/github/actions/workflow/status/ccrvlh/litestar-sso/test.yml?label=tests)
![Lint Workflow Status](https://img.shields.io/github/actions/workflow/status/ccrvlh/litestar-sso/lint.yml?label=ruff)
![Mypy Workflow Status](https://img.shields.io/github/actions/workflow/status/ccrvlh/litestar-sso/lint.yml?label=mypy)
![CodeQL Workflow Status](https://img.shields.io/github/actions/workflow/status/ccrvlh/litestar-sso/codeql-analysis.yml?label=CodeQL)
![Project License](https://img.shields.io/github/license/ccrvlh/litestar-sso)

> [!IMPORTANT]  
> This is a fork of the FastAPI SSO library, originally designed by [tomasvotava](https://tomasvotava.github.io).
> The only modification is that this was adapted to work with Litestar, and PR #189 was merged into this fork.
> Currently, this is best suited as building block, rather than a standalone library.

Litestar plugin to enable SSO to most common providers (such as Facebook login, Google login and login via
Microsoft Office 365 account).

This allows you to implement the famous `Login with Google/Facebook/Microsoft` buttons functionality on your
backend very easily.

**Documentation**: [https://tomasvotava.github.io/fastapi-sso/](https://tomasvotava.github.io/fastapi-sso/)

**Source Code**: [https://github.com/tomasvotava/fastapi-sso](https://github.com/tomasvotava/fastapi-sso/)

## Example:

```python
import os
from litestar import Litestar, Request, get
from litestar_sso import GoogleSSO

CLIENT_ID = os.environ["CLIENT_ID"]
CLIENT_SECRET = os.environ["CLIENT_SECRET"]

app = Litestar()

sso = GoogleSSO(
    client_id=CLIENT_ID,
    client_secret=CLIENT_SECRET,
    redirect_uri="http://localhost:5000/auth/callback",
    allow_insecure_http=True,
)


@get("/auth/login")
async def auth_init():
    """Initialize auth and redirect"""
    async with sso:
        return await sso.get_login_redirect(params={"prompt": "consent", "access_type": "offline"})


@get("/auth/callback")
async def auth_callback(request: Request):
    """Verify login"""
    async with sso:
        user = await sso.verify_and_process(request)
    return user
```

## Demo site

An awesome demo site was created and is maintained by even awesomer
[Chris Karvouniaris (@chrisK824)](https://github.com/chrisK824). Chris has also posted multiple
Medium articles about FastAPI and FastAPI SSO.

Be sure to see his tutorials, follow him and show him some appreciation!

Please see his [announcement](https://github.com/tomasvotava/fastapi-sso/discussions/150) with all the links.

Quick links for the eager ones:

- [Demo site](https://fastapi-sso-example.vercel.app/)
- [Medium articles](https://medium.com/@christos.karvouniaris247)

## Security warning

Please note that versions preceding `0.7.0` had a security vulnerability.
The SSO instance could share state between requests, which could lead to security issues.
**Please update to `0.7.0` or newer**.

Also, the preferred way of using the SSO instances is to use `with` statement, which will ensure the state is cleared.
See example below.

## Support this project

If you'd like to support this project, consider [buying me a coffee ☕](https://www.buymeacoffee.com/tomas.votava).
I tend to process Pull Requests faster when properly caffeinated 😉.

<a href="https://www.buymeacoffee.com/tomas.votava" target="_blank">
<img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png"
    alt="Buy Me A Coffee" style="height: 60px !important;width: 217px !important;" ></a>

## Supported login providers

### Official

- Google
- Microsoft
- Facebook
- Spotify
- Fitbit
- Github (credits to [Brandl](https://github.com/Brandl) for hint using `accept` header)
- generic (see [docs](https://tomasvotava.github.io/fastapi-sso/reference/sso.generic/))
- Notion
- Twitter (X)

### Contributed

- Kakao (by Jae-Baek Song - [thdwoqor](https://github.com/thdwoqor))
- Naver (by 1tang2bang92) - [1tang2bang92](https://github.com/1tang2bang92)
- Gitlab (by Alessandro Pischedda) - [Cereal84](https://github.com/Cereal84)
- Line (by Jimmy Yeh) - [jimmyyyeh](https://github.com/jimmyyyeh)
- LinkedIn (by Alessandro Pischedda) - [Cereal84](https://github.com/Cereal84)
- Yandex (by Akim Faskhutdinov) – [akimrx](https://github.com/akimrx)
- Seznam (by Tomas Koutek) - [TomasKoutek](https://github.com/TomasKoutek)

See [Contributing](#contributing) for a guide on how to contribute your own login provider.

## Installation

### Install using `pip`

```console
pip install fastapi-sso
```

### Install using `poetry`

```console
poetry add fastapi-sso
```

## Contributing

If you'd like to contribute and add your specific login provider, please see
[Contributing](https://tomasvotava.github.io/fastapi-sso/contributing) file.

