@@ -74,13 +74,27 @@ class DiscordOAuthClient:
74
74
Discord application client secret.
75
75
redirect_uri:
76
76
Discord application redirect URI.
77
+ proxy:
78
+ Optional proxy url
79
+ proxy_auth:
80
+ Optional aiohttp.BasicAuth proxy authentification
77
81
"""
78
82
79
- def __init__ (self , client_id , client_secret , redirect_uri , scopes = ("identify" ,)):
83
+ def __init__ (
84
+ self ,
85
+ client_id ,
86
+ client_secret ,
87
+ redirect_uri ,
88
+ scopes = ("identify" ,),
89
+ proxy = None ,
90
+ proxy_auth : aiohttp .BasicAuth = None ,
91
+ ):
80
92
self .client_id = client_id
81
93
self .client_secret = client_secret
82
94
self .redirect_uri = redirect_uri
83
95
self .scopes = "%20" .join (scope for scope in scopes )
96
+ self .proxy = proxy
97
+ self .proxy_auth = proxy_auth
84
98
self .client_session : aiohttp .ClientSession = aiohttp .ClientSession ()
85
99
86
100
def get_oauth_login_url (self , state : Optional [str ] = None ):
@@ -104,10 +118,20 @@ async def request(self, route: str, token: str = None, method: Literal["GET", "P
104
118
if token :
105
119
headers = {"Authorization" : f"Bearer { token } " }
106
120
if method == "GET" :
107
- async with self .client_session .get (f"{ DISCORD_API_URL } { route } " , headers = headers ) as resp :
121
+ async with self .client_session .get (
122
+ f"{ DISCORD_API_URL } { route } " ,
123
+ headers = headers ,
124
+ proxy = self .proxy ,
125
+ proxy_auth = self .proxy_auth ,
126
+ ) as resp :
108
127
data = await resp .json ()
109
128
elif method == "POST" :
110
- async with self .client_session .post (f"{ DISCORD_API_URL } { route } " , headers = headers ) as resp :
129
+ async with self .client_session .post (
130
+ f"{ DISCORD_API_URL } { route } " ,
131
+ headers = headers ,
132
+ proxy = self .proxy ,
133
+ proxy_auth = self .proxy_auth ,
134
+ ) as resp :
111
135
data = await resp .json ()
112
136
else :
113
137
raise Exception ("Other HTTP than GET and POST are currently not Supported" )
@@ -118,7 +142,12 @@ async def request(self, route: str, token: str = None, method: Literal["GET", "P
118
142
return data
119
143
120
144
async def get_token_response (self , payload : PAYLOAD ) -> TokenResponse :
121
- async with self .client_session .post (DISCORD_TOKEN_URL , data = payload ) as resp :
145
+ async with self .client_session .post (
146
+ DISCORD_TOKEN_URL ,
147
+ data = payload ,
148
+ proxy = self .proxy ,
149
+ proxy_auth = self .proxy_auth ,
150
+ ) as resp :
122
151
return await resp .json ()
123
152
124
153
async def get_access_token (self , code : str ) -> Tuple [str , str ]:
0 commit comments