Skip to main content

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.

Useful Links

Discord Server: https://discord.gg/DJ9xbbZAP5

Documentation is coming soon, don't worry.

Quickstart

Installing

I've finally published the library to PyPi! So now you can use pip.

pip install discord-oauth2.py

Example With Flask

Don't forget to replace all the client information with your application's own information. You can leave bot token empty if your not adding members to guilds.

import discordoauth2
from flask import Flask, request, redirect

client = discordoauth2.Client(849930878276993044, secret="very-secret-code",
redirect="https://findingfakeurlsisprettyhard.tv/oauth2", bot_token="bot-token-only-required-for-guild-joining-or-updating-linked-roles-metadata")
app = Flask(__name__)

client.update_linked_roles_metadata([
    {
        "type": 2,
        "key": "level",
        "name": "Level",
        "description": "The level the user is on"
    },
    {
        "type": 7,
        "key": "supporter",
        "name": "Supporter",
        "description": "Spent money to help the game"
    }
])

@app.route('/')
def main():
  return redirect(client.generate_uri(scope=["identify", "connections", "guilds", "role_connections.write"]))

@app.route("/oauth2")
def oauth2():
    code = request.args.get("code")

    access = client.exchange_code(code)

    access.update_metadata("Platform Name", "Username",  level=69, supporter=True)

    identify = access.fetch_identify()
    connections = access.fetch_connections()
    guilds = access.fetch_guilds()

    return f"""{identify}<br><br>{connections}<br><br>{guilds}"""

app.run("0.0.0.0", 8080)

Async usage

Asynchronous usage is also supported, you can use the async version of the library by importing discordoauth2.AsyncClient instead of discordoauth2.Client. The methods are the same, but they’re coroutines.

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

discord_oauth2_py-1.2.2.tar.gz (7.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

discord_oauth2_py-1.2.2-py3-none-any.whl (11.4 kB view details)

Uploaded Python 3

File details

Details for the file discord_oauth2_py-1.2.2.tar.gz.

File metadata

  • Download URL: discord_oauth2_py-1.2.2.tar.gz
  • Upload date:
  • Size: 7.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.22

File hashes

Hashes for discord_oauth2_py-1.2.2.tar.gz
Algorithm Hash digest
SHA256 bb17f3483abf9c90dfa3b68a607c6e05ed2f42a2d5bb1aa87e188a36d6b07e9f
MD5 986683205eeb0959b2aeaa964f92ecda
BLAKE2b-256 651c64df8019cd58adc5045700f6935afe8e2f466bee3d64e088bc66ba58ff1a

See more details on using hashes here.

File details

Details for the file discord_oauth2_py-1.2.2-py3-none-any.whl.

File metadata

File hashes

Hashes for discord_oauth2_py-1.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 4b04892c9199be537e846d819ee3a2795d6676e5734003a7868ae89fdd967218
MD5 4c507fa5cf0082e556ed673ee3a9ef1d
BLAKE2b-256 7ad80e242634e4eba80a073a0e1fc60470e38b9b96f9d784def218d13d0abb43

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page