Skip to content

Commit

Permalink
Getting Kakao auth_token from Desktop app
Browse files Browse the repository at this point in the history
  • Loading branch information
laggykiller committed Aug 30, 2024
1 parent 5971e55 commit 60a4fa1
Show file tree
Hide file tree
Showing 8 changed files with 431 additions and 65 deletions.
29 changes: 21 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,20 @@ To run in CLI mode, pass on any arguments
```
usage: sticker-convert.py [-h] [--version] [--no-confirm] [--no-progress] [--custom-presets CUSTOM_PRESETS] [--input-dir INPUT_DIR]
[--download-auto DOWNLOAD_AUTO | --download-signal DOWNLOAD_SIGNAL | --download-telegram DOWNLOAD_TELEGRAM | --download-line DOWNLOAD_LINE | --download-kakao DOWNLOAD_KAKAO | --download-viber DOWNLOAD_VIBER | --download-discord DOWNLOAD_DISCORD | --download-discord-emoji DOWNLOAD_DISCORD_EMOJI]
[--output-dir OUTPUT_DIR] [--author AUTHOR] [--title TITLE] [--export-signal | --export-telegram | --export-telegram-emoji | --export-viber | --export-whatsapp | --export-imessage] [--no-compress]
[--preset {auto,signal,telegram,telegram_emoji,whatsapp,line,kakao,viber,discord,discord_emoji,imessage_small,imessage_medium,imessage_large,custom}] [--steps STEPS] [--processes PROCESSES] [--fps-min FPS_MIN] [--fps-max FPS_MAX] [--fps-power FPS_POWER]
[--res-min RES_MIN] [--res-max RES_MAX] [--res-w-min RES_W_MIN] [--res-w-max RES_W_MAX] [--res-h-min RES_H_MIN] [--res-h-max RES_H_MAX] [--res-power RES_POWER] [--quality-min QUALITY_MIN] [--quality-max QUALITY_MAX] [--quality-power QUALITY_POWER]
[--color-min COLOR_MIN] [--color-max COLOR_MAX] [--color-power COLOR_POWER] [--duration-min DURATION_MIN] [--duration-max DURATION_MAX] [--padding-percent PADDING_PERCENT] [--bg-color BG_COLOR] [--vid-size-max VID_SIZE_MAX] [--img-size-max IMG_SIZE_MAX]
[--vid-format VID_FORMAT] [--img-format IMG_FORMAT] [--fake-vid] [--scale-filter SCALE_FILTER] [--quantize-method QUANTIZE_METHOD] [--cache-dir CACHE_DIR] [--default-emoji DEFAULT_EMOJI] [--signal-uuid SIGNAL_UUID] [--signal-password SIGNAL_PASSWORD] [--signal-get-auth]
[--telegram-token TELEGRAM_TOKEN] [--telegram-userid TELEGRAM_USERID] [--kakao-auth-token KAKAO_AUTH_TOKEN] [--kakao-get-auth] [--kakao-username KAKAO_USERNAME] [--kakao-password KAKAO_PASSWORD] [--kakao-country-code KAKAO_COUNTRY_CODE]
[--kakao-phone-number KAKAO_PHONE_NUMBER] [--line-get-auth] [--line-cookies LINE_COOKIES] [--viber-auth VIBER_AUTH] [--viber-get-auth VIBER_GET_AUTH] [--viber-bin-path VIBER_BIN_PATH] [--discord-get-auth] [--discord-token DISCORD_TOKEN] [--save-cred SAVE_CRED]
[--output-dir OUTPUT_DIR] [--author AUTHOR] [--title TITLE]
[--export-signal | --export-telegram | --export-telegram-emoji | --export-viber | --export-whatsapp | --export-imessage] [--no-compress]
[--preset {auto,signal,telegram,telegram_emoji,whatsapp,line,kakao,viber,discord,discord_emoji,imessage_small,imessage_medium,imessage_large,custom}]
[--steps STEPS] [--processes PROCESSES] [--fps-min FPS_MIN] [--fps-max FPS_MAX] [--fps-power FPS_POWER] [--res-min RES_MIN] [--res-max RES_MAX]
[--res-w-min RES_W_MIN] [--res-w-max RES_W_MAX] [--res-h-min RES_H_MIN] [--res-h-max RES_H_MAX] [--res-power RES_POWER]
[--quality-min QUALITY_MIN] [--quality-max QUALITY_MAX] [--quality-power QUALITY_POWER] [--color-min COLOR_MIN] [--color-max COLOR_MAX]
[--color-power COLOR_POWER] [--duration-min DURATION_MIN] [--duration-max DURATION_MAX] [--padding-percent PADDING_PERCENT]
[--bg-color BG_COLOR] [--vid-size-max VID_SIZE_MAX] [--img-size-max IMG_SIZE_MAX] [--vid-format VID_FORMAT] [--img-format IMG_FORMAT]
[--fake-vid] [--scale-filter SCALE_FILTER] [--quantize-method QUANTIZE_METHOD] [--cache-dir CACHE_DIR] [--default-emoji DEFAULT_EMOJI]
[--signal-uuid SIGNAL_UUID] [--signal-password SIGNAL_PASSWORD] [--signal-get-auth] [--telegram-token TELEGRAM_TOKEN]
[--telegram-userid TELEGRAM_USERID] [--kakao-auth-token KAKAO_AUTH_TOKEN] [--kakao-get-auth] [--kakao-get-auth-desktop]
[--kakao-bin-path KAKAO_BIN_PATH] [--kakao-username KAKAO_USERNAME] [--kakao-password KAKAO_PASSWORD] [--kakao-country-code KAKAO_COUNTRY_CODE]
[--kakao-phone-number KAKAO_PHONE_NUMBER] [--line-get-auth] [--line-cookies LINE_COOKIES] [--viber-auth VIBER_AUTH]
[--viber-get-auth VIBER_GET_AUTH] [--viber-bin-path VIBER_BIN_PATH] [--discord-get-auth] [--discord-token DISCORD_TOKEN] [--save-cred SAVE_CRED]
CLI for stickers-convert
Expand Down Expand Up @@ -257,7 +264,13 @@ Credentials options:
Set telegram user_id (From real account, not bot account). Required for uploading Telegram stickers.
--kakao-auth-token KAKAO_AUTH_TOKEN
Set Kakao auth_token. Required for downloading animated stickers from https://e.kakao.com/t/xxxxx
--kakao-get-auth Generate Kakao auth_token. Kakao username, password, country code and phone number are also required.
--kakao-get-auth Generate Kakao auth_token by simulating login. Kakao username, password, country code and phone number are also required.
--kakao-get-auth-desktop
Get Kakao auth_token from Kakao Desktop application.
(Only working on Windows.)
--kakao-bin-path KAKAO_BIN_PATH
Set Kakao Desktop application path for launching and getting auth_token.
Useful for portable installation.
--kakao-username KAKAO_USERNAME
Set Kakao username, which is email or phone number used for signing up Kakao account
Example: +447700900142
Expand Down
44 changes: 31 additions & 13 deletions docs/guide_kakao.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,39 +8,57 @@

- To download animated stickers, you have two options:
- Method 1: (RECOMMENDED) Get the share link of the emoticon pack from Kakao app on phone, which does not need auth_token (`https://emoticon.kakao.com/items/xxxxx`)
- Method 2: Use `https://e.kakao.com/t/xxxxx` which needs auth_token (Authorization header during request). **Note that this method may not work in some cases with unclear reasons, so use method 1.**
- Method 2-4: Use `https://e.kakao.com/t/xxxxx` which needs auth_token (Authorization header during request). **Note that this method may not work in some cases with unclear reasons, so use method 1.**

## Method 1: Get share link
![../imgs/kakao-share.jpeg](../imgs/kakao-share.jpeg)

## Method 2: Get auth_token
- You can get auth_token easily from GUI generate button, via CLI `--kakao-get-auth` or manually get from rooted Android device (You are recommended to do it on emulated Android device)
- Explanation of login information
- Username: Email or Phone number used for signing up Kakao account. (e.g. `+447700900142`)
- Password: Password of Kakao account
- Country code: Example would be 82 (For korea), 44 (For UK), 1 (For USA)
- Phone number: Phone number associated with your Kakao account. Used for send / receive verification code via SMS
- `sticker-convert` will simulate login to Android Kakao app
## Method 2: Get auth_token from KakaoTalk Desktop application
- `sticker-convert` will get auth_token from KakaoTalk Desktop application.
- Note that this only work on Windows.

GUI:
1. Download and Login to KakaoTalk Desktop
2. Press on `Generate` button in sticker-convert GUI
3. (Optional) if you installed KakaoTalk Desktop in non-default location, you may specify `Kakao app path`
4. Press on `Get auth_token` and wait

CLI:
1. Download and Login to KakaoTalk Desktop
2. Add `--kakao-get-auth-desktop` as arguments
3. (Optional) Add `--kakao-bin-path <KAKAO_APP_PATH>` if you installed KakaoTalk Desktop in non-default location
3. Execute command


## Method 3: Get auth_token by simulating login
- `sticker-convert` will simulate login to Android Kakao app to get auth_token
- You will send / receive verification code via SMS
- You will most likely receive verification code
- You have to send verification SMS if you requested to receive verification code too many times
- You maybe logged out of existing device
- The auth_token will expire after a period of time (About a week?), which you have to regenerate it.
- Explanation of login information
- Username: Email or Phone number used for signing up Kakao account. (e.g. `+447700900142`)
- Password: Password of Kakao account
- Country code: Example would be 82 (For korea), 44 (For UK), 1 (For USA)
- Phone number: Phone number associated with your Kakao account. Used for send / receive verification code via SMS

### How to get auth_token (GUI)
GUI:
1. Create KakaoTalk account on Phone
2. Press on `Generate` button in sticker-convert GUI
3. Enter account detail in the window
4. Press on `Login and get auth_token` and follow instructions

### How to get auth_token (CLI)
CLI:
1. Create KakaoTalk account on Phone
2. Add `--kakao-gen-auth-token --kakao-username <YOUR_USERNAME> --kakao-password <YOUR_PASSWORD> --kakao-country-code <YOUR_COUNTRY_CODE> --kakao-phone-number <YOUR_PHONE_NUMBER>` as arguments
2. Add `--kakao-get-auth --kakao-username <YOUR_USERNAME> --kakao-password <YOUR_PASSWORD> --kakao-country-code <YOUR_COUNTRY_CODE> --kakao-phone-number <YOUR_PHONE_NUMBER>` as arguments
- Note: If you had saved username, password, country_code and phone_number before, you may choose not to add them as arguments
- You may also add `--save-cred` to save the auth_token and login information for later use
3. Execute command and follow instructions

### How to get auth_token (Manually) or get emoticon ID
## Method 4: Get auth_token manually or get emoticon ID
You can manually get auth_token from rooted Android device (You are recommended to do it on emulated Android device)

1. Create KakaoTalk account on Phone
2. Install Android Studio and create an emulated device, then install KakaoTalk on the device
3. Install BurpSuite
Expand Down
16 changes: 16 additions & 0 deletions src/sticker_convert/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from sticker_convert.job_option import CompOption, CredOption, InputOption, OutputOption
from sticker_convert.utils.auth.get_discord_auth import GetDiscordAuth
from sticker_convert.utils.auth.get_kakao_auth import GetKakaoAuth
from sticker_convert.utils.auth.get_kakao_desktop_auth import GetKakaoDesktopAuth
from sticker_convert.utils.auth.get_line_auth import GetLineAuth
from sticker_convert.utils.auth.get_signal_auth import GetSignalAuth
from sticker_convert.utils.auth.get_viber_auth import GetViberAuth
Expand Down Expand Up @@ -168,6 +169,7 @@ def cli(self) -> None:
flags_cred_bool = (
"signal_get_auth",
"kakao_get_auth",
"kakao_get_auth_desktop",
"line_get_auth",
"discord_get_auth",
)
Expand Down Expand Up @@ -483,6 +485,20 @@ def get_opt_cred(self, args: Namespace) -> CredOption:

self.cb.msg(f"Got auth_token successfully: {auth_token}")

if args.kakao_get_auth_desktop:
get_kakao_desktop_auth = GetKakaoDesktopAuth(
cb_ask_str=self.cb.ask_str,
)
kakao_bin_path = None
if args.kakao_bin_path:
kakao_bin_path = args.kakao_bin_path
auth_token, msg = get_kakao_desktop_auth.get_cred(kakao_bin_path)

if auth_token:
opt_cred.kakao_auth_token = auth_token

self.cb.msg(msg)

if args.signal_get_auth:
m = GetSignalAuth(cb_msg=self.cb.msg, cb_ask_str=self.cb.ask_str)

Expand Down
28 changes: 23 additions & 5 deletions src/sticker_convert/downloaders/download_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,24 @@ def __init__(
self.cb_return = cb_return

def download_multiple_files(
self, targets: List[Tuple[str, Path]], retries: int = 3, headers: Optional[dict[Any, Any]] = None, **kwargs: Any
self,
targets: List[Tuple[str, Path]],
retries: int = 3,
headers: Optional[dict[Any, Any]] = None,
**kwargs: Any,
) -> None:
anyio.run(
partial(self.download_multiple_files_async, targets, retries, headers, **kwargs)
partial(
self.download_multiple_files_async, targets, retries, headers, **kwargs
)
)

async def download_multiple_files_async(
self, targets: List[Tuple[str, Path]], retries: int = 3, headers: Optional[dict[Any, Any]] = None, **kwargs: Any
self,
targets: List[Tuple[str, Path]],
retries: int = 3,
headers: Optional[dict[Any, Any]] = None,
**kwargs: Any,
) -> None:
# targets format: [(url1, dest2), (url2, dest2), ...]
self.cb.put(
Expand All @@ -47,7 +57,13 @@ async def download_multiple_files_async(
async with anyio.create_task_group() as tg:
for url, dest in targets:
tg.start_soon(
self.download_file_async, client, url, dest, retries, headers, **kwargs
self.download_file_async,
client,
url,
dest,
retries,
headers,
**kwargs,
)

async def download_file_async(
Expand All @@ -61,7 +77,9 @@ async def download_file_async(
) -> None:
self.cb.put(f"Downloading {url}")
for retry in range(retries):
response = await client.get(url, follow_redirects=True, headers=headers, **kwargs)
response = await client.get(
url, follow_redirects=True, headers=headers, **kwargs
)

if response.is_success:
async with await anyio.open_file(dest, "wb+") as f:
Expand Down
1 change: 1 addition & 0 deletions src/sticker_convert/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ def declare_variables(self) -> None:
self.kakao_password_var = StringVar(self)
self.kakao_country_code_var = StringVar(self)
self.kakao_phone_number_var = StringVar(self)
self.kakao_bin_path_var = StringVar(self)
self.line_cookies_var = StringVar(self)
self.viber_auth_var = StringVar(self)
self.viber_bin_path_var = StringVar(self)
Expand Down
Loading

0 comments on commit 60a4fa1

Please sign in to comment.