Files
AstralCalendar/auth/oauth_callback.go
T
2026-08-06 14:37:53 -04:00

32 lines
613 B
Go

package auth
import (
"fmt"
"net/http"
)
// this is usually served at /callback
func OAuthCallback(w http.ResponseWriter, r *http.Request) {
state := r.FormValue("state")
code := r.FormValue("code")
stateCookie, err := r.Cookie("oauth_state")
if err != nil {
http.Error(w, "Invalid state parameter", http.StatusBadRequest)
return
}
if state != stateCookie.Value {
http.Error(w, "Invalid state parameter", http.StatusBadRequest)
return
}
http.SetCookie(w, &http.Cookie{
Name: "oauth_state",
Value: "",
Path: "/",
MaxAge: -1,
})
fmt.Printf("Handling some OAuth, %s\n", code)
}