diff options
author | Trygve Aaberge <trygveaa@gmail.com> | 2022-09-18 13:06:39 +0200 |
---|---|---|
committer | Trygve Aaberge <trygveaa@gmail.com> | 2022-09-18 16:36:55 +0200 |
commit | 9c5a4b1bc92a35df53fef6e0e3620e3db50ea734 (patch) | |
tree | eae335927cce5c20f71d04f9febfa9d8f8110a28 | |
parent | f205c37dc9e43e7c159a5d36a1b11b78365492ea (diff) | |
download | wee-slack-9c5a4b1bc92a35df53fef6e0e3620e3db50ea734.tar.gz |
Support including the d-s cookie
According to one comment it was necessary for them to include this
cookie as well.
-rw-r--r-- | README.md | 3 | ||||
-rwxr-xr-x | extract_token_from_browser.py | 18 | ||||
-rw-r--r-- | wee_slack.py | 6 |
3 files changed, 22 insertions, 5 deletions
@@ -171,6 +171,9 @@ token (but not the token itself). If you're worried about this, you can use the 8. Return to WeeChat and run `/slack register <token>:<cookie>`. 9. Reload the script with `/python reload slack`. +Note that in some cases it may be necessary to include the `d-s` cookie as +well. If so, you can supply it in this format `<token>:d=<d_cookie>;d-s=<d-s_cookie>`. + If you use Firefox, you can run the `extract_token_from_browser.py` script to get the tokens and cookies for all the teams you're logged into: diff --git a/extract_token_from_browser.py b/extract_token_from_browser.py index d571120..5798ba0 100755 --- a/extract_token_from_browser.py +++ b/extract_token_from_browser.py @@ -34,10 +34,21 @@ except StopIteration: cookies_path = default_profile_path.joinpath("cookies.sqlite") con = sqlite3.connect(f"file:{cookies_path}?immutable=1", uri=True) -cookies_query = "SELECT value FROM moz_cookies WHERE host = '.slack.com' AND name = 'd'" -cookie_d_value = con.execute(cookies_query).fetchone()[0] +cookie_d_query = ( + "SELECT value FROM moz_cookies WHERE host = '.slack.com' AND name = 'd'" +) +cookie_d_value = con.execute(cookie_d_query).fetchone()[0] +cookie_ds_query = ( + "SELECT value FROM moz_cookies WHERE host = '.slack.com' AND name = 'd-s'" +) +cookie_ds_values = con.execute(cookie_ds_query).fetchone() con.close() +if cookie_ds_values: + cookie_value = f"d={cookie_d_value};d-s={cookie_ds_values[0]}" +else: + cookie_value = cookie_d_value + local_storage_path = default_profile_path.joinpath("webappsstore.sqlite") con = sqlite3.connect(f"file:{local_storage_path}?immutable=1", uri=True) local_storage_query = "SELECT value FROM webappsstore2 WHERE key = 'localConfig_v2'" @@ -49,7 +60,6 @@ teams = [ team for team in local_config["teams"].values() if not team["id"].startswith("E") ] register_commands = [ - f"{team['name']}:\n/slack register {team['token']}:{cookie_d_value}" - for team in teams + f"{team['name']}:\n/slack register {team['token']}:{cookie_value}" for team in teams ] print("\n\n".join(register_commands)) diff --git a/wee_slack.py b/wee_slack.py index 3e80089..e0df044 100644 --- a/wee_slack.py +++ b/wee_slack.py @@ -1453,7 +1453,11 @@ class SlackRequest(object): if ":" in self.token: token, cookie = self.token.split(":", 1) self.token = token - self.cookies["d"] = cookie + if cookie.startswith("d="): + for name, value in [c.split("=") for c in cookie.split(";")]: + self.cookies[name] = value + else: + self.cookies["d"] = cookie self.callback = callback self.domain = "api.slack.com" self.reset() |