get basic information about the user
This commit is contained in:
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user