Spaces:
No application file
No application file
Upload bot_oauth.py
Browse files- bot_oauth.py +54 -0
bot_oauth.py
ADDED
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import json
|
2 |
+
|
3 |
+
import aiohttp
|
4 |
+
|
5 |
+
headers = {
|
6 |
+
'User-Agent':
|
7 |
+
'Mozilla/5.0 (Linux; Android 11; WayDroid x86_64 Device Build/RQ3A.211001.001; ) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/109.0.5414.118 Safari/537.36 BingSapphire/24.1.410310303',
|
8 |
+
'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8'
|
9 |
+
}
|
10 |
+
|
11 |
+
|
12 |
+
async def get_auth_url(client_id):
|
13 |
+
oauth_url = 'https://login.live.com/oauth20_authorize.srf'
|
14 |
+
redirect_uri = 'https://login.live.com/oauth20_desktop.srf'
|
15 |
+
scope = 'service::bing.com::MBI_SSL'
|
16 |
+
response_type = 'code'
|
17 |
+
return f'{oauth_url}?client_id={client_id}&redirect_uri={redirect_uri}&response_type={response_type}&scope={scope}'
|
18 |
+
|
19 |
+
|
20 |
+
async def auth(authCode, client_id):
|
21 |
+
cookies = None
|
22 |
+
has_sydney = True
|
23 |
+
chat_uri = 'https://www.bing.com/sydchat'
|
24 |
+
signin_uri = 'https://ssl.bing.com/fd/auth/signin'
|
25 |
+
token_uri = 'https://login.live.com/oauth20_token.srf'
|
26 |
+
redirect_uri = 'https://login.live.com/oauth20_desktop.srf'
|
27 |
+
grant_type = 'authorization_code'
|
28 |
+
|
29 |
+
uri = f'{token_uri}?client_id={client_id}&code={authCode}&redirect_uri={redirect_uri}&grant_type={grant_type}'
|
30 |
+
|
31 |
+
async with aiohttp.ClientSession(headers=headers) as session:
|
32 |
+
access_token = None
|
33 |
+
cookies = None
|
34 |
+
async with session.post(uri, data={
|
35 |
+
'client_id': client_id,
|
36 |
+
'code': authCode,
|
37 |
+
'redirect_uri': redirect_uri,
|
38 |
+
'grant_type': 'authorization_code'
|
39 |
+
}) as response:
|
40 |
+
if response.status == 200:
|
41 |
+
js = await response.json()
|
42 |
+
access_token = js["access_token"]
|
43 |
+
if access_token:
|
44 |
+
async with session.get(f'{signin_uri}?action=token&provider=windows_live_id&save_token=0&token={access_token}') as response:
|
45 |
+
if response.status == 200:
|
46 |
+
js = json.loads(await response.text())
|
47 |
+
if js['success']:
|
48 |
+
cookies = session.cookie_jar
|
49 |
+
if cookies:
|
50 |
+
async with session.get(chat_uri) as response:
|
51 |
+
if response.status != 200:
|
52 |
+
cookies = None
|
53 |
+
has_sydney = False
|
54 |
+
return cookies, has_sydney
|