Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nwunderly/starlette-discord
"Login with Discord" support for Starlette and FastAPI
https://github.com/nwunderly/starlette-discord
discord-api discord-oauth2-extension fastapi login-with-discord oauth2 starlette starlette-discord
Last synced: 2 days ago
JSON representation
"Login with Discord" support for Starlette and FastAPI
- Host: GitHub
- URL: https://github.com/nwunderly/starlette-discord
- Owner: nwunderly
- License: mit
- Created: 2021-01-10T02:59:14.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2024-09-10T00:25:57.000Z (4 months ago)
- Last Synced: 2024-12-17T14:07:24.430Z (10 days ago)
- Topics: discord-api, discord-oauth2-extension, fastapi, login-with-discord, oauth2, starlette, starlette-discord
- Language: Python
- Homepage: https://starlette-discord.rtfd.io
- Size: 104 KB
- Stars: 32
- Watchers: 3
- Forks: 11
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Starlette-Discord
"Login with Discord" support for Starlette and FastAPIstarlette-discord is a Discord OAuth2 module intended for use with Starlette and FastAPI.
#### Installing
starlette-discord can be installed with the command
```sh
# Linux
python3 -m pip install -U starlette-discord# Windows
python -m pip install -U starlette-discord
```To install the development version of the library directly from source:
```sh
$ git clone https://github.com/nwunderly/starlette-discord
$ cd starlette-discord
$ python3 -m pip install -U .
```### Quickstart
Below is an example FastAPI app implementing Discord's OAuth flow to identify the user.
```py
import uvicorn
from fastapi import FastAPI
from starlette_discord import DiscordOAuthClientclient_id = "YOUR APP'S CLIENT ID HERE"
client_secret = "YOUR APP'S CLIENT SECRET HERE"
redirect_uri = "http://localhost:8000/callback"app = FastAPI()
discord_client = DiscordOAuthClient(client_id, client_secret, redirect_uri)@app.get('/login')
async def start_login():
return discord_client.redirect()@app.get('/callback')
async def finish_login(code: str):
user = await discord_client.login(code)
print(user)
return useruvicorn.run(app)
```To begin the OAuth authorization flow with this app, visit `http://localhost:8000/login`.