From f76d715cb9b4982bdaf06e9d245359bd2be358f9 Mon Sep 17 00:00:00 2001 From: Gregory Wells Date: Thu, 6 Aug 2026 19:38:04 -0400 Subject: [PATCH] get basic information about the user --- caldav/dav_server.go | 8 ++++---- main/main.go | 22 ++++++++++++++++++++++ 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/caldav/dav_server.go b/caldav/dav_server.go index 1b39aad..360261d 100644 --- a/caldav/dav_server.go +++ b/caldav/dav_server.go @@ -20,11 +20,11 @@ const neededXML string = ` ` -var client *http.Client +var BuildInClient *http.Client var serverURL string func InitDavClient(url string) { - client = &http.Client{} + BuildInClient = &http.Client{} serverURL = url } @@ -55,7 +55,7 @@ func GetCalDAVData(username string, password string) SimpleCalDavData { req.Header.Set("Depth", "1") req.Header.Set("Content-Type", "application/xml") - resp, err := client.Do(req) + resp, err := BuildInClient.Do(req) if err != nil { fmt.Print(err.Error()) } @@ -120,7 +120,7 @@ func GetCalendarData(cal Calandar, username string, password string) Calandar { req.Header.Set("Depth", "1") req.Header.Set("Content-Type", "application/xml") - resp, err := client.Do(req) + resp, err := BuildInClient.Do(req) if err != nil { fmt.Print(err.Error()) } diff --git a/main/main.go b/main/main.go index 6359764..4c38263 100644 --- a/main/main.go +++ b/main/main.go @@ -2,6 +2,8 @@ package main import ( "context" + "encoding/json" + "fmt" "net/http" "astraltech.xyz/calendar/v2/auth" @@ -9,6 +11,10 @@ import ( "astraltech.xyz/calendar/v2/webserver" ) +type UserInfo struct { + Email string `json:"email"` +} + func handleUser(w http.ResponseWriter, r *http.Request) { // Load the stored token token, err := auth.TestTokenStore.Load() @@ -19,6 +25,22 @@ func handleUser(w http.ResponseWriter, r *http.Request) { // Create an HTTP client that attaches the access token client := auth.OAuthConfigs[0].Client(context.Background(), token) + + // Fetch user information from GitHub API + resp, err := client.Get("https://account.astraltech.xyz/application/o/userinfo/") + if err != nil { + http.Error(w, "Failed to fetch user: "+err.Error(), http.StatusInternalServerError) + return + } + defer resp.Body.Close() + + var usersInfo UserInfo + if err := json.NewDecoder(resp.Body).Decode(&usersInfo); err != nil { + http.Error(w, "Failed to decode response", http.StatusInternalServerError) + return + } + + fmt.Printf("The users email is %s\n", usersInfo.Email) } func main() {