refactor: вынести VK-авторизацию в client/internal/vkauth
Этап 2 плана рефакторинга. Выносит слой VK credentials/captcha/throttle/
lockout из client/main.go в отдельный пакет с инжектируемым хуком token-chain
для тестов.
Интерфейс:
- vkauth.Client{GetCredentials, HandleAuthError, ResetErrors, LockoutUntilUnix}
- vkauth.IsAuthError (package-level)
- vkauth.DefaultAutoSolve / AutoSolveFunc / ManualSolveFunc
Wire-формат и флаги CLI не изменены. client/main.go: 1967 → 1380.
This commit is contained in:
1 parent
322e8db4fa
commit
5bf6dd0399
9 files changed
+1035
-633
No files matched your search
@@ -0,0 +1,46 @@
|
||||
package vkauth
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"github.com/cacggghp/vk-turn-proxy/client/internal/browserprofile"
|
||||
"github.com/cacggghp/vk-turn-proxy/client/internal/captcha"
|
||||
|
||||
tlsclient "github.com/bogdanfinn/tls-client"
|
||||
)
|
||||
|
||||
// DefaultAutoSolve drives the in-page widget flow. It loads a saved real
|
||||
// browser profile when available so the captcha origin sees consistent
|
||||
// fingerprints across the page load and the solve POST.
|
||||
func DefaultAutoSolve(
|
||||
ctx context.Context,
|
||||
captchaErr *captcha.Error,
|
||||
streamID int,
|
||||
client tlsclient.HttpClient,
|
||||
profile browserprofile.Profile,
|
||||
) (string, error) {
|
||||
log.Printf("[STREAM %d] [Captcha] Solving captcha...", streamID)
|
||||
|
||||
if captchaErr.SessionToken == "" {
|
||||
return "", fmt.Errorf("no session_token in redirect_uri for auto-solve")
|
||||
}
|
||||
if captchaErr.RedirectURI == "" {
|
||||
return "", fmt.Errorf("no redirect_uri for auto-solve")
|
||||
}
|
||||
|
||||
var savedProfile *browserprofile.Saved
|
||||
if sp, err := browserprofile.Load(); err == nil {
|
||||
log.Printf("[STREAM %d] [Captcha] Using saved real browser profile", streamID)
|
||||
savedProfile = sp
|
||||
profile = sp.Profile
|
||||
}
|
||||
|
||||
successToken, err := captcha.Solve(ctx, captchaErr, streamID, client, profile, savedProfile)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
log.Printf("[STREAM %d] [Captcha] solver succeeded", streamID)
|
||||
return successToken, nil
|
||||
}
|
||||
Reference in new issue
Block a user