Fix SN API authorization

This commit is contained in:
ekzyis 2023-04-16 22:03:14 +02:00
parent c0e2078039
commit 7b841abf2f
2 changed files with 7 additions and 7 deletions

View File

@ -1 +1 @@
NEXT_AUTH_CSRF_TOKEN=
AUTH_COOKIE=

12
sn.go
View File

@ -41,8 +41,8 @@ type UpsertLinkResponse struct {
}
var (
SnApiUrl string
SnApiToken string
SnApiUrl string
SnAuthCookie string
)
func init() {
@ -51,10 +51,10 @@ func init() {
if err != nil {
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()
if SnApiToken == "" {
log.Fatal("NEXT_AUTH_CSRF_TOKEN not set")
if SnAuthCookie == "" {
log.Fatal("AUTH_COOKIE not set")
}
}
@ -69,7 +69,7 @@ func MakeStackerNewsRequest(body GraphQLPayload) *http.Response {
panic(err)
}
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
resp, err := client.Do(req)