Giter Site home page Giter Site logo

nwunderly / starlette-discord Goto Github PK

View Code? Open in Web Editor NEW
31.0 3.0 11.0 106 KB

"Login with Discord" support for Starlette and FastAPI

Home Page: https://starlette-discord.rtfd.io

License: MIT License

Python 100.00%
discord-api login-with-discord starlette fastapi oauth2 starlette-discord discord-oauth2-extension

starlette-discord's Introduction

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.