Fix SN API authorization
This commit is contained in:
parent
c0e2078039
commit
7b841abf2f
|
@ -1 +1 @@
|
||||||
NEXT_AUTH_CSRF_TOKEN=
|
AUTH_COOKIE=
|
10
sn.go
10
sn.go
|
@ -42,7 +42,7 @@ type UpsertLinkResponse struct {
|
||||||
|
|
||||||
var (
|
var (
|
||||||
SnApiUrl string
|
SnApiUrl string
|
||||||
SnApiToken string
|
SnAuthCookie string
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
@ -51,10 +51,10 @@ func init() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("Error loading .env file")
|
log.Fatal("Error loading .env file")
|
||||||
}
|
}
|
||||||
flag.StringVar(&SnApiToken, "NEXT_AUTH_CSRF_TOKEN", "", "Token required for authorizing requests to stacker.news/api/graphql")
|
flag.StringVar(&SnAuthCookie, "AUTH_COOKIE", "", "Cookie required for authorizing requests to stacker.news/api/graphql")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
if SnApiToken == "" {
|
if SnAuthCookie == "" {
|
||||||
log.Fatal("NEXT_AUTH_CSRF_TOKEN not set")
|
log.Fatal("AUTH_COOKIE not set")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,7 +69,7 @@ func MakeStackerNewsRequest(body GraphQLPayload) *http.Response {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
req.Header.Set("Content-Type", "application/json")
|
req.Header.Set("Content-Type", "application/json")
|
||||||
req.Header.Set("Cookie", fmt.Sprintf("__Host-next-auth.csrf-token=%s", SnApiToken))
|
req.Header.Set("Cookie", SnAuthCookie)
|
||||||
|
|
||||||
client := http.DefaultClient
|
client := http.DefaultClient
|
||||||
resp, err := client.Do(req)
|
resp, err := client.Do(req)
|
||||||
|
|
Loading…
Reference in New Issue