move calendar endpoint into new file
This commit is contained in:
@@ -0,0 +1,37 @@
|
|||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
auth.OAuthProviders[0].UserInfoEndpoint()
|
||||||
|
|
||||||
|
client := auth.OAuthConfigs[0].Client(context.Background(), token)
|
||||||
|
|
||||||
|
resp, err := client.Get(auth.OAuthProviders[0].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)
|
||||||
|
}
|
||||||
+2
-38
@@ -1,51 +1,15 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"astraltech.xyz/calendar/v2/auth"
|
"astraltech.xyz/calendar/v2/auth"
|
||||||
"astraltech.xyz/calendar/v2/caldav"
|
"astraltech.xyz/calendar/v2/caldav"
|
||||||
"astraltech.xyz/calendar/v2/webserver"
|
"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()
|
|
||||||
if err != nil {
|
|
||||||
http.Error(w, "Not authenticated", http.StatusUnauthorized)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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() {
|
func main() {
|
||||||
auth.CreateTestOAuth()
|
auth.SetAuth()
|
||||||
read_config()
|
read_config()
|
||||||
|
|
||||||
caldav.InitDavClient(serverConfig.URL)
|
caldav.InitDavClient(serverConfig.URL)
|
||||||
|
|
||||||
webserver.ServeLoginPage("/login", webserver.CustomizableLoginData{
|
webserver.ServeLoginPage("/login", webserver.CustomizableLoginData{
|
||||||
|
|||||||
Reference in New Issue
Block a user