Skip to content
This repository was archived by the owner on Dec 12, 2023. It is now read-only.

Commit b0b637c

Browse files
committed
login: add manual option
Closes #1 Closes #3 Signed-off-by: Sumner Evans <[email protected]>
1 parent 66a710b commit b0b637c

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

examples/manual-login.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import asyncio
2+
3+
from linkedin_messaging import LinkedInMessaging
4+
from linkedin_messaging.api_objects import URN
5+
6+
urn = URN("urn:li:fs_conversation:2-YWM2YTJmYjUtNTdjMS00ZjlmLTgwMDUtOWYxMmMxNjY4M2FlXzAxMg==")
7+
8+
9+
async def main():
10+
linkedin = LinkedInMessaging()
11+
await linkedin.login_manual(
12+
"FOO",
13+
"ajax:1234567890",
14+
)
15+
16+
assert await linkedin.logged_in()
17+
18+
try:
19+
# Get a list of all of the conversations for the given user.
20+
conversations = await linkedin.get_conversations()
21+
for c in conversations.elements:
22+
print(c)
23+
24+
# Get a specific conversation by URN.
25+
convo_resp = await linkedin.get_conversation(urn)
26+
for element in convo_resp.elements:
27+
print(element)
28+
29+
finally:
30+
await linkedin.close()
31+
32+
33+
loop = asyncio.get_event_loop()
34+
loop.run_until_complete(main())

linkedin_messaging/linkedin.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,14 @@ async def logged_in(self) -> bool:
147147
logging.exception(f"Failed getting the user profile: {e}")
148148
return False
149149

150+
async def login_manual(self, li_at: str, jsessionid: str, new_session: bool = True):
151+
if new_session:
152+
if self.session:
153+
await self.session.close()
154+
self.session = aiohttp.ClientSession()
155+
self.session.cookie_jar.update_cookies({"li_at": li_at, "JSESSIONID": jsessionid})
156+
self.session.headers["csrf-token"] = jsessionid.strip('"')
157+
150158
async def login(self, email: str, password: str, new_session: bool = True):
151159
if new_session:
152160
if self.session:

0 commit comments

Comments
 (0)