Skip to content

Commit

Permalink
try to fix auth 1
Browse files Browse the repository at this point in the history
  • Loading branch information
jasondborneman committed Dec 20, 2023
1 parent 3f1a015 commit af15e47
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions Bsky/Bsky.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"log"
"net/http"
"os"
"strings"
"time"
)

Expand All @@ -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"`
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit af15e47

Please sign in to comment.