From af15e4705cf64990029c9acc097cfe115e60c9ac Mon Sep 17 00:00:00 2001 From: jasondborneman Date: Wed, 20 Dec 2023 10:12:37 -0500 Subject: [PATCH] try to fix auth 1 --- Bsky/Bsky.go | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/Bsky/Bsky.go b/Bsky/Bsky.go index 7f8ea71..a1983f0 100644 --- a/Bsky/Bsky.go +++ b/Bsky/Bsky.go @@ -8,7 +8,6 @@ import ( "log" "net/http" "os" - "strings" "time" ) @@ -19,6 +18,11 @@ type BskyAuth struct { refreshJwt string } +type BskyAuthPost struct { + Identifier string `json:"identifier"` + Password string `json:"password"` +} + type BskyImageWithAlt struct { Alt string `json:"alt"` Image string `json:"image"` @@ -44,9 +48,18 @@ func PostWithMedia(message string, media [][]byte) error { } handle := os.Getenv("BSKY_USER") pass := os.Getenv("BSKY_PASS") + bskyAuthPost := &BskyAuthPost{ + Identifier: handle, + Password: pass, + } + var authBuf bytes.Buffer + encodeErr := json.NewEncoder(&authBuf).Encode(bskyAuthPost) + if encodeErr != nil { + log.Fatalf("Error encoding Bsky Auth Post: %s", encodeErr) + return encodeErr + } url := fmt.Sprintf("%s/xrpc/com.atproto.server.createSession", bskyUri) - body := strings.NewReader(fmt.Sprintf(`{"identifier":%s,"password":%s}`, handle, pass)) - resp, authErr := bskyClient.Post(url, "application/json", body) + resp, authErr := bskyClient.Post(url, "application/json", &authBuf) if authErr != nil { log.Fatalf("Error authenticating to Bsky: %s", authErr) return authErr @@ -93,7 +106,7 @@ func PostWithMedia(message string, media [][]byte) error { }) } var buf bytes.Buffer - encodeErr := json.NewEncoder(&buf).Encode(bskyMediaPost) + encodeErr = json.NewEncoder(&buf).Encode(bskyMediaPost) if encodeErr != nil { log.Fatalf("Error encoding Bsky Media Post: %s", encodeErr) return encodeErr