Skip to main content

"Login with Discord" support for Starlette and FastAPI.

Project description

Starlette-Discord

"Login with Discord" support for Starlette and FastAPI

starlette-discord is a Discord OAuth2 module intended for use with Starlette and FastAPI.

Installing

starlette-discord can be installed with the command

# 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:

$ 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.

import uvicorn
from fastapi import FastAPI
from starlette_discord import DiscordOAuthClient

client_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 user

uvicorn.run(app)

To begin the OAuth authorization flow with this app, visit http://localhost:8000/login.

Project details


Download files

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

Files for starlette-discord, version 0.2.0
Filename, size File type Python version Upload date Hashes
Filename, size starlette_discord-0.2.0-py3.8.egg (13.4 kB) File type Egg Python version 0.2.0 Upload date Hashes View
Filename, size starlette_discord-0.2.0-py3-none-any.whl (14.5 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size starlette-discord-0.2.0.tar.gz (14.1 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page