Skip to content

Commit

Permalink
feat: fastapi refs
Browse files Browse the repository at this point in the history
  • Loading branch information
ccrvlh committed Nov 3, 2024
1 parent aabe0b4 commit 8f2047a
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 27 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# FastAPI SSO
# Litestar SSO

![Supported Python Versions](https://img.shields.io/pypi/pyversions/litestar-sso)
[![Test coverage](https://codecov.io/gh/tomasvotava/litestar-sso/graph/badge.svg?token=SIFCTVSSOS)](https://codecov.io/gh/tomasvotava/litestar-sso)
Expand All @@ -11,7 +11,7 @@
![Project License](https://img.shields.io/github/license/tomasvotava/litestar-sso)
![PyPi Version](https://img.shields.io/pypi/v/litestar-sso)

FastAPI plugin to enable SSO to most common providers (such as Facebook login, Google login and login via
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
Expand All @@ -25,7 +25,7 @@ backend very easily.

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.
Medium articles about Litestar and Litestar SSO.

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

Expand Down
4 changes: 2 additions & 2 deletions docs/how-to-guides/state-return-url.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ Example:

```python

from fastapi import Request
from fastapi.responses import RedirectResponse
from litestar import Request
from litestar.responses import RedirectResponse

google_sso = GoogleSSO("client-id", "client-secret")

Expand Down
16 changes: 8 additions & 8 deletions docs/how-to-guides/use-with-fastapi-security.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# Using with fastapi's Security
# Using with litestar's Security

Even though `litestar-sso` does not try to solve login and authentication, it is clear that you
will probably mostly use it to protect your endpoints. This is why it is important to know how
to use it with fastapi's security.
to use it with litestar's security.

You were asking how to put the lock 🔒 icon to your Swagger docs
in [this issue](https://github.com/tomasvotava/litestar-sso/issues/33). This is how you do it.

## Requirements

- `fastapi` - obviously
- `litestar` - obviously
- `litestar-sso` - duh
- `python-jose[cryptography]` - to sign and verify our JWTs

Expand All @@ -27,15 +27,15 @@ the token was not changed.
This makes JWTs very helpful, because it's the thing that comes from the user that you can actually trust.

In this example, we will save the JWT into a cookie so that the user sends it with every request. We will
also use fastapi's `Depends` to make sure that the user is authenticated before accessing the endpoint.
also use litestar's `Depends` to make sure that the user is authenticated before accessing the endpoint.

## Example

```python
import datetime # to calculate expiration of the JWT
from fastapi import FastAPI, Depends, HTTPException, Security, Request
from fastapi.responses import RedirectResponse
from fastapi.security import APIKeyCookie # this is the part that puts the lock icon to the docs
from litestar import Litestar, Depends, HTTPException, Security, Request
from litestar.responses import RedirectResponse
from litestar.security import APIKeyCookie # this is the part that puts the lock icon to the docs
from litestar_sso.sso.google import GoogleSSO # pip install litestar-sso
from litestar_sso.sso.base import OpenID

Expand Down Expand Up @@ -112,7 +112,7 @@ if __name__ == "__main__":

Visit [`http://127.0.0.1:5000/docs/`](http://127.0.0.1:5000/docs/)

![Swagger docs with lock icon](./fastapi-security.png)
![Swagger docs with lock icon](./litestar-security.png)

### Accessing the `/protected` endpoint before login

Expand Down
6 changes: 3 additions & 3 deletions docs/tutorials.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Fill in the `Authorized redirect URIs` field with `http://localhost:3000/google/
Then, copy the `Client ID` and `Client secret` and paste them into the following code:

```python
from fastapi import FastAPI
from litestar import Litestar
from starlette.requests import Request
from litestar_sso.sso.google import GoogleSSO

Expand Down Expand Up @@ -46,12 +46,12 @@ You should be redirected to Google login page. After successful login, you shoul

## Using SSO as a dependency

You may use SSO as a dependency in your FastAPI application.
You may use SSO as a dependency in your Litestar application.
This is useful if you want to use the same SSO instance in multiple endpoints and make sure the state is cleared after
the request is processed. You may even omit the `with` statement in this case.

```python
from fastapi import Depends, FastAPI, Request
from litestar import Depends, Litestar, Request
from litestar_sso.sso.google import GoogleSSO

app = Litestar()
Expand Down
2 changes: 1 addition & 1 deletion litestar_sso/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""FastAPI plugin to enable SSO to most common providers.
"""Litestar plugin to enable SSO to most common providers.
(such as Facebook login, Google login and login via Microsoft Office 365 account)
"""
Expand Down
10 changes: 5 additions & 5 deletions litestar_sso/sso/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def wrapper(*args: P.args, **kwargs: P.kwargs) -> T:
if not args[0]._in_stack:
warnings.warn(
"Please make sure you are using SSO provider in an async context (using 'async with provider:'). "
"See https://github.com/tomasvotava/fastapi-sso/issues/186 for more information.",
"See https://github.com/tomasvotava/litestar-sso/issues/186 for more information.",
category=SecurityWarning,
stacklevel=1,
)
Expand Down Expand Up @@ -357,10 +357,10 @@ async def verify_and_process(
redirect_uri: Optional[str] = None,
convert_response: Union[Literal[True], Literal[False]] = True,
) -> Union[Optional[OpenID], Optional[Dict[str, Any]]]:
"""Processes the login given a FastAPI (Starlette) Request object. This should be used for the /callback path.
"""Processes the login given a Litestar (Starlette) Request object. This should be used for the /callback path.
Args:
request (Request): FastAPI or Starlette request object.
request (Request): Litestar or Starlette request object.
params (Optional[Dict[str, Any]]): Additional query parameters to pass to the provider.
headers (Optional[Dict[str, Any]]): Additional headers to pass to the provider.
redirect_uri (Optional[str]): Overrides the `redirect_uri` specified on this instance.
Expand Down Expand Up @@ -404,7 +404,7 @@ async def verify_and_process(
def __enter__(self) -> "SSOBase":
warnings.warn(
"SSO Providers are supposed to be used in async context, please change 'with provider' to "
"'async with provider'. See https://github.com/tomasvotava/fastapi-sso/issues/186 for more information.",
"'async with provider'. See https://github.com/tomasvotava/litestar-sso/issues/186 for more information.",
DeprecationWarning,
stacklevel=1,
)
Expand Down Expand Up @@ -495,7 +495,7 @@ async def process_login(
Args:
code (str): The authorization code.
request (Request): FastAPI or Starlette request object.
request (Request): Litestar or Starlette request object.
params (Optional[Dict[str, Any]]): Additional query parameters to pass to the provider.
additional_headers (Optional[Dict[str, Any]]): Additional headers to be added to all requests.
redirect_uri (Optional[str]): Overrides the `redirect_uri` specified on this instance.
Expand Down
2 changes: 1 addition & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,6 @@ nav:
- how-to-guides/http-development.md
- how-to-guides/redirect-uri-request-time.md
- how-to-guides/state-return-url.md
- how-to-guides/use-with-fastapi-security.md
- how-to-guides/use-with-litestar-security.md
- how-to-guides/key-error.md
- contributing.md
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
[tool.poetry]
name = "litestar-sso"
version = "0.15.0"
description = "FastAPI plugin to enable SSO to most common providers (such as Facebook login, Google login and login via Microsoft Office 365 Account)"
version = "0.16.0"
description = "litestar plugin to enable SSO to most common providers (such as Facebook login, Google login and login via Microsoft Office 365 Account)"
authors = ["Tomas Votava <info@tomasvotava.eu>"]
readme = "README.md"
license = "MIT"
repository = "https://github.com/tomasvotava/litestar-sso"
homepage = "https://tomasvotava.github.io/litestar-sso/"
documentation = "https://tomasvotava.github.io/litestar-sso/"
keywords = [
"fastapi",
"litestar",
"sso",
"oauth",
"google",
Expand Down
2 changes: 1 addition & 1 deletion tests/test_race_condition.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# See [!186](https://github.com/tomasvotava/fastapi-sso/issues/186)
# See [!186](https://github.com/tomasvotava/litestar-sso/issues/186)
# Author: @parikls

import asyncio
Expand Down

0 comments on commit 8f2047a

Please sign in to comment.