MCPcopy Index your code
hub / github.com/Preloading/TwitterAPIBridge / Authenticate

Function Authenticate

bluesky/auth.go:24–62  ·  view source on GitHub ↗
(username, password string)

Source from the content-addressed store, hash-verified

22}
23
24func Authenticate(username, password string) (*AuthResponse, *string, error) {
25 _, userPDS, err := GetUserAuthData(username)
26 if err != nil {
27 return nil, nil, err
28 }
29
30 url := *userPDS + "/xrpc/com.atproto.server.createSession"
31
32 authReq := AuthRequest{
33 Identifier: username,
34 Password: password,
35 }
36
37 reqBody, err := json.Marshal(authReq)
38 if err != nil {
39 return nil, nil, err
40 }
41
42 resp, err := SendRequest(nil, http.MethodPost, url, bytes.NewBuffer(reqBody))
43 if err != nil {
44 return nil, nil, err
45 }
46 defer resp.Body.Close()
47
48 if resp.StatusCode != http.StatusOK {
49 bodyBytes, _ := io.ReadAll(resp.Body)
50 bodyString := string(bodyBytes)
51 fmt.Println("Response Status:", resp.StatusCode)
52 fmt.Println("Response Body:", bodyString)
53 return nil, nil, errors.New("authentication failed")
54 }
55
56 var authResp AuthResponse
57 if err := json.NewDecoder(resp.Body).Decode(&authResp); err != nil {
58 return nil, nil, err
59 }
60
61 return &authResp, userPDS, nil
62}
63
64func RefreshToken(pds string, refreshToken string) (*AuthResponse, error) {
65 url := pds + "/xrpc/com.atproto.server.refreshSession"

Callers

nothing calls this directly

Calls 2

GetUserAuthDataFunction · 0.85
SendRequestFunction · 0.85

Tested by

no test coverage detected