Use Discord's OAuth2 effortlessly! Turns the auth code to a access token and the access token into scope infomation.
Project description
DiscordOAuth2.py
Use Discord's OAuth2 effortlessly! Turns the auth code to a access token and the access token into scope infomation.
Notice: I don't know how to make my library work with
pip install
so you'll have to copy the source code and paste it into your workspace.
Using DiscordOAuth2.py with Flask
You can try out a working example here: https://DiscordOAuth2py.treeben77.repl.co
from flask import Flask, redirect, request
from discordoauth2 import discordOauth2
import os
app = Flask('Discord OAuth2 Example')
client = discordOauth2(client=your-client-id, secret="your-client-secret",
redirect="your-redirect-url", token="your-bot-token (optional)")
# Replace your-client-id with your application's client id, replace your-client-secret with your client secret and replace your-redirect-url with the url that discord will redirect users to once they complete OAuth2.
# If you want to add users to a guild, insert a bot token with CREATE_INSTANT_INVITE permissions in the guilds you want to add users to.
@app.route('/')
def main():
# Your OAuth2 url, you can make one a https://discord.dev
return redirect("https://discord.com/api/oauth2/authorize")
@app.route('/oauth2')
def oauth():
tokenObject = client.exchange_code(token=request.args.get('code'))
print("refresh token: "+tokenObject.refresh_token)
# returns basic data about the user, including username, avatar and badges, if the email scope was parsed, it will also return their email.
identify = tokenObject.access.identify()
# returns visible and hidden connections such as GitHub, YouTube or Twitter.
connections = tokenObject.access.connections()
# returns a list of guilds that the user is in
guilds = tokenObject.access.guilds()
# returns a member object for the provided guild
guilds_member = tokenObject.access.guilds_member(guilds[0]["id"])
# makes a user join a guild, bot token provided must have CREATE_INSTANT_INVITE in that guild
tokenObject.access.guilds_join(guild-id-here)
return f"{identify}<br><br>{connections}<br><br>{guilds}<br><br>guild data for the first guild: {guilds_member}"
app.run(host="0.0.0.0", port=8080)
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for discord_oauth2.py-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a4c621664e3e92055e65b5c8cc5de1330d7c38a3b0061d1421b33d93f95226fc |
|
MD5 | 62a691c60f05d60017d70c8ea37bdf7c |
|
BLAKE2b-256 | 89a30578c7009a8788fc269bbceb9044c38fb1df5a9af8d514bc77210fc4582d |