Skip to content

Commit 209fba5

Browse files
authored
Update to support new changes to discordOAuth2.py
1 parent 4ed7114 commit 209fba5

File tree

1 file changed

+16
-21
lines changed

1 file changed

+16
-21
lines changed

README.md

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,32 @@
22
Use Discord's OAuth2 effortlessly! Turns the auth code to a access token and the access token into scope infomation.
33

44
### Using DiscordOAut2.py with Flask
5-
65
```python
76
from flask import Flask, redirect, request
87
from threading import Thread
9-
import discordoauth2 as oauth2
8+
from discordoauth2 import discordOauth2
109
import os
1110

12-
app = Flask('')
13-
oauth2.client({
14-
'client_id': '849<example>993044', #the client id for your application
15-
'client_secret': os.environ['oauth2_secret'], #the client secret for your application. Be super-extra-very-we-are-not-kidding-like-really-be-secure-make-sure-your-info-is-not-in-your-source-code careful with this.
16-
'redirect_uri': 'https://example.com/oauth2', #the redirect for the uri below
17-
'bot_token': os.environ['bot_token'] #the token for your app's bot, only required if you need to use guild.join
18-
})
11+
app = Flask('Discord OAuth2 Example')
12+
client = discordOauth2(client=159985870458322944, secret=os.environ['oauth2_secret'],
13+
redirect="https://example.com", token=os.environ['bot_token'])
14+
#Replace the int above with your application's client ID and the redirect with the redirect URL with the redirect URL this flask hosts. add your oauth2 secret and bot token to a .env file.
15+
#token could be None. token must be a valid Bot Token or None. Only required if your application adds users to a guild.
1916

20-
oauth2_uri = "https://discord.com/api/oauth2/authorize?client_id=849<example>993044&redirect_uri=https%3A%2F%2Fexample.com%2Foauth2&response_type=code&scope=identify"
17+
@app.route('/')
18+
def main():
19+
return redirect("https://discord.com/api/oauth2/authorize?client_id=159985870458322944&redirect_uri=https%3A%2F%2Fexample.com%2Foauth2&response_type=code&scope=identify%20email%20connections%20guilds%20guilds.join")
2120

2221
@app.route('/oauth2')
2322
def oauth():
2423
code = request.args.get('code')
25-
if not code:
26-
return redirect(oauth2_uri)
27-
else:
28-
token = oauth2.exchange_code(code)
29-
if str(token) == """{'error': 'invalid_request', 'error_description': 'Invalid "code" in request.'}""":
30-
return redirect(oauth2_uri)
31-
identify = oauth2.get_identify(token['access_token'])
32-
connections = oauth2.get_connections(token['access_token'])
33-
guilds = oauth2.get_guilds(token['access_token'])
34-
oauth2.join_guild(token['access_token'], 849912914450448395)
35-
return f'{identify}<br/><br/>{connections}<br/><br/>{guilds}'
24+
tokenObject = client.exchange_code(token=code)
25+
26+
identify = tokenObject.identify()
27+
connections = tokenObject.connections()
28+
guilds = tokenObject.guilds()
29+
tokenObject.join_guild(336642139381301249)
30+
return f"{identify}<br/><br/>{connections}<br/><br/>{guilds}"
3631

3732
def run():
3833
app.run(host="0.0.0.0", port=8080)

0 commit comments

Comments
 (0)