Skip to content

Commit ce05735

Browse files
committed
refactor(authentication): remove legacy duplicated cookie handling functions
1 parent 9668111 commit ce05735

File tree

2 files changed

+1
-89
lines changed

2 files changed

+1
-89
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ uv run main.py --no-headless --no-lazy-init
259259
- `--no-lazy-init` - Login to LinkedIn immediately instead of waiting for the first tool call
260260
- `--get-cookie` - Login with email and password and extract the LinkedIn cookie
261261
- `--cookie {cookie}` - Pass a specific LinkedIn cookie for login
262+
- `--help` - Show help
262263

263264
**Claude Desktop:**
264265
```**json**

linkedin_mcp_server/config/secrets.py

Lines changed: 0 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -8,60 +8,14 @@
88
from linkedin_mcp_server.exceptions import CredentialsNotFoundError
99

1010
from .providers import (
11-
get_cookie_from_keyring,
1211
get_credentials_from_keyring,
1312
get_keyring_name,
14-
save_cookie_to_keyring,
1513
save_credentials_to_keyring,
1614
)
1715

1816
logger = logging.getLogger(__name__)
1917

2018

21-
def has_authentication() -> bool:
22-
"""Check if authentication is available without triggering interactive setup."""
23-
config = get_config()
24-
25-
# Check environment variable
26-
if config.linkedin.cookie:
27-
return True
28-
29-
# Check keyring if enabled
30-
if config.linkedin.use_keyring:
31-
cookie = get_cookie_from_keyring()
32-
if cookie:
33-
return True
34-
35-
return False
36-
37-
38-
def get_authentication() -> str:
39-
"""Get LinkedIn cookie from keyring, environment, or interactive setup."""
40-
config = get_config()
41-
42-
# First, try environment variable
43-
if config.linkedin.cookie:
44-
logger.info("Using LinkedIn cookie from environment")
45-
return config.linkedin.cookie
46-
47-
# Second, try keyring if enabled
48-
if config.linkedin.use_keyring:
49-
cookie = get_cookie_from_keyring()
50-
if cookie:
51-
logger.info(f"Using LinkedIn cookie from {get_keyring_name()}")
52-
return cookie
53-
54-
# If in non-interactive mode and no cookie found, raise error
55-
if config.chrome.non_interactive:
56-
raise CredentialsNotFoundError(
57-
"No LinkedIn cookie found. Please provide cookie via "
58-
"environment variable (LINKEDIN_COOKIE) or run with --get-cookie to obtain one."
59-
)
60-
61-
# Otherwise, prompt for cookie or setup
62-
return prompt_for_authentication()
63-
64-
6519
def get_credentials() -> Dict[str, str]:
6620
"""Get LinkedIn credentials from config, keyring, or prompt (legacy for --get-cookie)."""
6721
config = get_config()
@@ -89,49 +43,6 @@ def get_credentials() -> Dict[str, str]:
8943
return prompt_for_credentials()
9044

9145

92-
def prompt_for_authentication() -> str:
93-
"""Prompt user for LinkedIn cookie or setup via login."""
94-
print("🔗 LinkedIn MCP Server Setup")
95-
96-
# Ask if user has a cookie
97-
has_cookie = inquirer.confirm("Do you have a LinkedIn cookie?", default=False)
98-
99-
if has_cookie:
100-
cookie = inquirer.text("LinkedIn Cookie", validate=lambda _, x: len(x) > 10)
101-
if save_cookie_to_keyring(cookie):
102-
logger.info(f"Cookie stored securely in {get_keyring_name()}")
103-
else:
104-
logger.warning("Could not store cookie in system keyring.")
105-
logger.info("Your cookie will only be used for this session.")
106-
return cookie
107-
else:
108-
# Login flow to get cookie
109-
return setup_cookie_from_login()
110-
111-
112-
def setup_cookie_from_login() -> str:
113-
"""Login with credentials and capture cookie."""
114-
from linkedin_mcp_server.setup import capture_cookie_from_credentials
115-
116-
print("🔑 LinkedIn login required to obtain cookie")
117-
credentials = prompt_for_credentials()
118-
119-
# Use existing cookie capture functionality
120-
cookie = capture_cookie_from_credentials(
121-
credentials["email"], credentials["password"]
122-
)
123-
124-
if cookie:
125-
if save_cookie_to_keyring(cookie):
126-
logger.info(f"Cookie stored securely in {get_keyring_name()}")
127-
else:
128-
logger.warning("Could not store cookie in system keyring.")
129-
logger.info("Your cookie will only be used for this session.")
130-
return cookie
131-
else:
132-
raise CredentialsNotFoundError("Failed to obtain LinkedIn cookie")
133-
134-
13546
def prompt_for_credentials() -> Dict[str, str]:
13647
"""Prompt user for LinkedIn credentials and store them securely."""
13748
print(f"🔑 LinkedIn credentials required (will be stored in {get_keyring_name()})")

0 commit comments

Comments
 (0)