Python Wrapper for discords oauth2
Support for the following endpoints- exchange code for token
- refresh token
- get user connections
- get user guilds
- get user info
Python 3.8 or higher is required Install from pip
python -m pip install -U auth-cord
Install from github
python -m pip install -U git+https://github.com/cibere/auth-cord # requires git to be installed
Get user infoQ: I don't have a webserver, can I still use discords oauth?
A: Yes! You can set the redirect_url tohttps://api.cibere.dev/auth_cord
, and tell the user to give your bot the given code.
import asyncio
import auth_cord
# creating our authorization object
auth = auth_cord.Authorization(
client_id=123,
client_secret="...",
redirect_url="...",
)
# creating our client instance and passing our authorization
client = auth_cord.Client(authorization=auth)
async def main():
# starting our client
async with client:
# exchanging our code with discord for a token
token = await client.exchange_code("...")
# getting the users connections
user = await client.get_user_info(
token.token
) # 'token' is a 'auth_cord.token.Token' object
# printing the users id
print(user.id)
# checking if this file is the one that was run
if __name__ == "__main__":
# if so, run the main function
asyncio.run(main())
See the examples folder for a full list of examples