Handle state in OAuth client

This commit is contained in:
2026-08-06 14:37:53 -04:00
parent c305b53f11
commit 4644a7d3f4
+21 -1
View File
@@ -7,5 +7,25 @@ import (
// this is usually served at /callback // this is usually served at /callback
func OAuthCallback(w http.ResponseWriter, r *http.Request) { func OAuthCallback(w http.ResponseWriter, r *http.Request) {
fmt.Printf("Getting my OAuth callback") 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)
} }