get token from OAuth provider

This commit is contained in:
2026-08-06 14:46:08 -04:00
parent 4644a7d3f4
commit 16a38c972c
4 changed files with 28 additions and 2 deletions
+24 -2
View File
@@ -1,8 +1,11 @@
package auth
import (
"fmt"
"context"
"log"
"net/http"
"golang.org/x/oauth2"
)
// this is usually served at /callback
@@ -27,5 +30,24 @@ func OAuthCallback(w http.ResponseWriter, r *http.Request) {
MaxAge: -1,
})
fmt.Printf("Handling some OAuth, %s\n", code)
verifierCookie, err := r.Cookie("pkce_verifier")
if err != nil {
http.Error(w, "Missing PKCE verifier", http.StatusBadRequest)
return
}
verifier := verifierCookie.Value
token, err := OAuthConfigs[0].Exchange(context.Background(), code, oauth2.VerifierOption(verifier))
if err != nil {
http.Error(w, "Failed to exchange token: "+err.Error(), http.StatusInternalServerError)
return
}
// Store the token securely
if err := tokenStore.Save(token); err != nil {
log.Printf("Failed to save token: %v", err)
}
http.Redirect(w, r, "/user", http.StatusTemporaryRedirect)
}