readd in password auth
This commit is contained in:
+32
-2
@@ -5,12 +5,15 @@ import (
|
|||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"astraltech.xyz/calendar/v2/caldav"
|
||||||
"astraltech.xyz/calendar/v2/webserver"
|
"astraltech.xyz/calendar/v2/webserver"
|
||||||
|
ics "github.com/arran4/golang-ical"
|
||||||
"golang.org/x/oauth2"
|
"golang.org/x/oauth2"
|
||||||
)
|
)
|
||||||
|
|
||||||
var tokenStore TokenStore
|
var TestTokenStore TokenStore
|
||||||
|
|
||||||
func generateState() (string, error) {
|
func generateState() (string, error) {
|
||||||
b := make([]byte, 32)
|
b := make([]byte, 32)
|
||||||
@@ -21,7 +24,34 @@ func generateState() (string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func HandlePasswordAuth(authData webserver.PasswordAuthData) bool {
|
func HandlePasswordAuth(authData webserver.PasswordAuthData) bool {
|
||||||
fmt.Printf("%s, %s\n", authData.Username, authData.Password)
|
calDavData := caldav.GetCalDAVData(authData.Username, authData.Password)
|
||||||
|
|
||||||
|
fmt.Printf("Users display name: %s\n", calDavData.DisplayName)
|
||||||
|
fmt.Printf("Calandar Count: %d\n", len(calDavData.Calandars))
|
||||||
|
for i := range len(calDavData.Calandars) {
|
||||||
|
calDavData.Calandars[i] = caldav.GetCalendarData(calDavData.Calandars[i], authData.Username, authData.Password)
|
||||||
|
|
||||||
|
fmt.Printf("Cal %d is named %s\n", i, calDavData.Calandars[i].DisplayName)
|
||||||
|
fmt.Printf("\tLink to cal: %s\n", calDavData.Calandars[i].Link)
|
||||||
|
fmt.Printf("\tEvent count: %d\n", len(calDavData.Calandars[i].Events))
|
||||||
|
for j := range len(calDavData.Calandars[i].Events) {
|
||||||
|
cal, err := ics.ParseCalendar(strings.NewReader(calDavData.Calandars[i].Events[j].CalData))
|
||||||
|
if err != nil {
|
||||||
|
fmt.Print(err.Error())
|
||||||
|
}
|
||||||
|
events := cal.Events()
|
||||||
|
for k := range len(events) {
|
||||||
|
name := events[k].GetProperty(ics.ComponentProperty(ics.PropertySummary)).Value
|
||||||
|
start, _ := events[k].GetStartAt()
|
||||||
|
end, _ := events[k].GetEndAt()
|
||||||
|
time := end.Sub(start)
|
||||||
|
fmt.Printf("\t\tEvent name: %s\n", name)
|
||||||
|
fmt.Printf("\t\t\tEvent start date: %s\n", end.UTC().String())
|
||||||
|
fmt.Printf("\t\t\tEvent length date: %s\n", time.String())
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -28,5 +28,5 @@ func CreateTestOAuth() {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
OAuthConfigs = append(OAuthConfigs, oauthConfig)
|
OAuthConfigs = append(OAuthConfigs, oauthConfig)
|
||||||
tokenStore = TokenStore{filePath: "token.json"}
|
TestTokenStore = TokenStore{filePath: "token.json"}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ func OAuthCallback(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Store the token securely
|
// Store the token securely
|
||||||
if err := tokenStore.Save(token); err != nil {
|
if err := TestTokenStore.Save(token); err != nil {
|
||||||
log.Printf("Failed to save token: %v", err)
|
log.Printf("Failed to save token: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ go 1.26.1
|
|||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/arran4/golang-ical v0.3.5 // indirect
|
github.com/arran4/golang-ical v0.3.5 // indirect
|
||||||
github.com/coreos/go-oidc/v3 v3.20.0 // indirect
|
github.com/coreos/go-oidc/v3 v3.20.0
|
||||||
github.com/go-jose/go-jose/v4 v4.1.4 // indirect
|
github.com/go-jose/go-jose/v4 v4.1.4 // indirect
|
||||||
golang.org/x/oauth2 v0.36.0 // indirect
|
golang.org/x/oauth2 v0.36.0
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,11 +1,26 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
|
"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"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
auth.CreateTestOAuth()
|
auth.CreateTestOAuth()
|
||||||
read_config()
|
read_config()
|
||||||
@@ -16,6 +31,8 @@ func main() {
|
|||||||
AuthRequestFunction: auth.HandleAuthRequest,
|
AuthRequestFunction: auth.HandleAuthRequest,
|
||||||
})
|
})
|
||||||
webserver.ServeWebpage("/callback", auth.OAuthCallback)
|
webserver.ServeWebpage("/callback", auth.OAuthCallback)
|
||||||
|
webserver.ServeWebpage("/user", handleUser)
|
||||||
|
|
||||||
webserver.EnableLogoRoute()
|
webserver.EnableLogoRoute()
|
||||||
webserver.EnableStaticRoute()
|
webserver.EnableStaticRoute()
|
||||||
webserver.ServeWebserver()
|
webserver.ServeWebserver()
|
||||||
|
|||||||
Reference in New Issue
Block a user