add authtoken auth

This commit is contained in:
Valentine 2024-02-20 21:43:19 +03:00
parent 8d81775809
commit 6a5df36aed

27
auth.go
View file

@ -401,13 +401,14 @@ func (s *Scraper) SetCookies(cookies []*http.Cookie) {
s.client.Jar.SetCookies(twURL, cookies) s.client.Jar.SetCookies(twURL, cookies)
} }
func (s *Scraper) SetAuthToken(authToken string, ct0 string) { func (s *Scraper) ClearCookies() {
var ( s.client.Jar, _ = cookiejar.New(nil)
cookies []*http.Cookie }
expires = time.Date(1, time.January, 1, 0, 0, 0, 0, time.UTC)
)
cookies = append(cookies, &http.Cookie{ // Auth using auth_token and ct0 cookies
func (s *Scraper) SetAuthToken(authToken string, ct0 string) {
expires := time.Date(1, time.January, 1, 0, 0, 0, 0, time.UTC)
cookies := []*http.Cookie{{
Name: "auth_token", Name: "auth_token",
Value: authToken, Value: authToken,
Path: "", Path: "",
@ -419,9 +420,8 @@ func (s *Scraper) SetAuthToken(authToken string, ct0 string) {
HttpOnly: false, HttpOnly: false,
SameSite: 0, SameSite: 0,
Raw: "", Raw: "",
}) Unparsed: nil,
}, {
cookies = append(cookies, &http.Cookie{
Name: "ct0", Name: "ct0",
Value: ct0, Value: ct0,
Path: "", Path: "",
@ -433,13 +433,10 @@ func (s *Scraper) SetAuthToken(authToken string, ct0 string) {
HttpOnly: false, HttpOnly: false,
SameSite: 0, SameSite: 0,
Raw: "", Raw: "",
}) Unparsed: nil,
}}
s.SetCookies(cookies)
}
func (s *Scraper) ClearCookies() { s.SetCookies(cookies)
s.client.Jar, _ = cookiejar.New(nil)
} }
func (s *Scraper) sign(method string, ref *url.URL) string { func (s *Scraper) sign(method string, ref *url.URL) string {