-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathauth.go
More file actions
42 lines (38 loc) Β· 1.1 KB
/
Copy pathauth.go
File metadata and controls
42 lines (38 loc) Β· 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package metaai
import (
"context"
"io"
"net/http"
)
// scrapeAccessToken fetches https://meta.ai with the current cookies and extracts
// the ecto1: access token from the page HTML. Challenge handling is a TODO
// since the live capture did not encounter a challenge page).
//
// Returns ("", nil) when the page loads but no token is present.
func (c *Client) scrapeAccessToken(ctx context.Context) (string, error) {
req, err := http.NewRequestWithContext(ctx, http.MethodGet, MetaAIHomeURL, nil)
if err != nil {
return "", err
}
attachCookies(req, c.cookies)
req.Header.Set("User-Agent", c.cfg.UserAgent)
resp, err := c.http.Do(req)
if err != nil {
return "", err
}
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
if err != nil {
return "", err
}
html := string(body)
// If challenge-page detection succeeds, surface
// ErrRegionBlocked β automated challenge resolution is not yet implemented.
if cu := detectChallengePage(html); cu != "" {
return "", ErrRegionBlocked
}
if resp.StatusCode >= 400 {
return "", ErrNotAuthenticated
}
return extractAccessToken(html), nil
}