36 lines
841 B
Go
36 lines
841 B
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"fmt"
|
|
"net/http"
|
|
|
|
"astraltech.xyz/calendar/v2/auth"
|
|
)
|
|
|
|
func handleUser(w http.ResponseWriter, r *http.Request) {
|
|
token, err := auth.TestTokenStore.Load()
|
|
if err != nil {
|
|
http.Error(w, "Not authenticated", http.StatusUnauthorized)
|
|
return
|
|
}
|
|
|
|
client := auth.DefaultProvider.Config.Client(context.Background(), token)
|
|
|
|
resp, err := client.Get(auth.DefaultProvider.Provider.UserInfoEndpoint())
|
|
if err != nil {
|
|
http.Error(w, "Failed to fetch user: "+err.Error(), http.StatusInternalServerError)
|
|
return
|
|
}
|
|
defer resp.Body.Close()
|
|
|
|
var usersInfo auth.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)
|
|
}
|