refactor(vkauth): разбить token.go на файлы по шагам

token.go теперь тонкий оркестратор (~75 строк). Каждый шаг VK-токена в своём
файле:
- token_request.go: хелпер doRequest (POST + browser-заголовки + JSON)
- token_anon.go: fetchAnonToken (шаг 1, login.vk.ru)
- token_call.go: fetchCallToken + captcha-loop + solveCaptcha (шаг 2)
- token_oksession.go: fetchOkRuSession (шаг 3, calls.okcdn.ru)
- token_creds.go: fetchTurnCreds (шаг 4, vchat.joinConversationByLink)

Публичный API (Client, getTokenChain, tokenChainFn) не изменён. Поведение
идентично оригиналу.
This commit is contained in:
samosvalishe committed 2026-05-21 01:26:21 +03:00
1 parent d82258f844
commit 0e2d42c912
6 files changed
+385 -245

No files matched your search

+29
View File
@@ -0,0 +1,29 @@
package vkauth
import (
"context"
"fmt"
neturl "net/url"
"github.com/samosvalishe/btp/internal/client/browserprofile"
"github.com/google/uuid"
tlsclient "github.com/bogdanfinn/tls-client"
)
// fetchOkRuSession performs step 3 of the token chain: it obtains an anonymous
// ok.ru session_key via auth.anonymLogin.
func (c *Client) fetchOkRuSession(ctx context.Context, httpClient tlsclient.HttpClient, profile browserprofile.Profile) (string, error) {
sessionData := fmt.Sprintf(`{"version":2,"device_id":"%s","client_version":1.1,"client_type":"SDK_JS"}`, uuid.New())
data := fmt.Sprintf("session_data=%s&method=auth.anonymLogin&format=JSON&application_key=CGMMEJLGDIHBABABA",
neturl.QueryEscape(sessionData))
resp, err := c.doRequest(ctx, httpClient, profile, data, "https://calls.okcdn.ru/fb.do")
if err != nil {
return "", err
}
sessionKey, ok := resp["session_key"].(string)
if !ok {
return "", fmt.Errorf("missing session_key in response: %v", resp)
}
return sessionKey, nil
}