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 }