|
161 | 161 | " base_url = \"https://discord.com/oauth2/authorize\"\n", |
162 | 162 | " token_url = \"https://discord.com/api/oauth2/token\"\n", |
163 | 163 | " revoke_url = \"https://discord.com/api/oauth2/token/revoke\"\n", |
| 164 | + " info_url = \"https://discord.com/api/users/@me\"\n", |
164 | 165 | " id_key = 'id'\n", |
165 | 166 | "\n", |
166 | 167 | " def __init__(self, client_id, client_secret, is_user=False, perms=0, scope=None, **kwargs):\n", |
|
169 | 170 | " self.perms = perms\n", |
170 | 171 | " super().__init__(client_id, client_secret, scope=scope, **kwargs)\n", |
171 | 172 | "\n", |
172 | | - " def login_link(self):\n", |
| 173 | + " def login_link(self, redirect_uri=None, scope=None, state=None):\n", |
| 174 | + " use_scope = scope or self.scope\n", |
173 | 175 | " d = dict(response_type='code', client_id=self.client_id,\n", |
174 | | - " integration_type=self.integration_type, scope=self.scope) #, permissions=self.perms, prompt='consent')\n", |
| 176 | + " integration_type=self.integration_type, scope=use_scope)\n", |
| 177 | + " if state: d['state'] = state\n", |
| 178 | + " if redirect_uri: d['redirect_uri'] = redirect_uri\n", |
175 | 179 | " return f'{self.base_url}?' + urlencode(d)\n", |
176 | 180 | "\n", |
177 | | - " def parse_response(self, code):\n", |
| 181 | + " def parse_response(self, code, redirect_uri=None):\n", |
178 | 182 | " headers = {'Content-Type': 'application/x-www-form-urlencoded'}\n", |
179 | | - " data = dict(grant_type='authorization_code', code=code)#, redirect_uri=self.redirect_uri)\n", |
| 183 | + " data = dict(grant_type='authorization_code', code=code)\n", |
| 184 | + " if redirect_uri: data['redirect_uri'] = redirect_uri\n", |
180 | 185 | " r = httpx.post(self.token_url, data=data, headers=headers, auth=(self.client_id, self.client_secret))\n", |
181 | 186 | " r.raise_for_status()\n", |
182 | 187 | " self.parse_request_body_response(r.text)" |
|
0 commit comments