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:
1 parent
d82258f844
commit
0e2d42c912
6 files changed
+385
-245
No files matched your search
@@ -0,0 +1,30 @@
|
||||
package vkauth
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/samosvalishe/btp/internal/client/browserprofile"
|
||||
|
||||
tlsclient "github.com/bogdanfinn/tls-client"
|
||||
)
|
||||
|
||||
// fetchAnonToken performs step 1 of the token chain: it exchanges the app
|
||||
// client_id/client_secret for an anonymous access token from login.vk.ru.
|
||||
func (c *Client) fetchAnonToken(ctx context.Context, httpClient tlsclient.HttpClient, profile browserprofile.Profile, creds VKCredentials) (string, error) {
|
||||
data := fmt.Sprintf("client_id=%s&token_type=messages&client_secret=%s&version=1&app_id=%s",
|
||||
creds.ClientID, creds.ClientSecret, creds.ClientID)
|
||||
resp, err := c.doRequest(ctx, httpClient, profile, data, "https://login.vk.ru/?act=get_anonym_token")
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
dataMap, ok := resp["data"].(map[string]any)
|
||||
if !ok {
|
||||
return "", fmt.Errorf("unexpected anon token response: %v", resp)
|
||||
}
|
||||
token, ok := dataMap["access_token"].(string)
|
||||
if !ok {
|
||||
return "", fmt.Errorf("missing access_token in response: %v", resp)
|
||||
}
|
||||
return token, nil
|
||||
}
|
||||
Reference in new issue
Block a user