Compare commits
24 Commits
Author | SHA1 | Date | |
---|---|---|---|
8f1654a3cf | |||
6851467d46 | |||
aceb53efe9 | |||
0be0c38fb1 | |||
d946069f6a | |||
cdbfe64f5c | |||
6eb24cc601 | |||
2b61ef233d | |||
d6148f289a | |||
e1987287e3 | |||
98d2a6c3b2 | |||
1e0ddbc0ee | |||
22607d3601 | |||
a553e9e93a | |||
63f764d1c5 | |||
19ddd10164 | |||
97aae89ce9 | |||
1af505196a | |||
02b33167ef | |||
98ea369664 | |||
62c27305f9 | |||
7864ed98e6 | |||
57d7e0cc69 | |||
c29340669c |
56
CHANGELOG.md
56
CHANGELOG.md
@ -1,3 +1,59 @@
|
|||||||
|
## [1.0.24](http://gitea.gitea.svc.cluster.local:3000/djpbessems/ContainerImage.SpamasaurusRex/compare/v1.0.23...v1.0.24) (2024-03-11)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* Refactor to use filesystem storage instead of cookies ([aceb53e](http://gitea.gitea.svc.cluster.local:3000/djpbessems/ContainerImage.SpamasaurusRex/commit/aceb53efe914ddc4ffd9c9ff3bad3917c138fd69))
|
||||||
|
|
||||||
|
## [1.0.23](http://gitea.gitea.svc.cluster.local:3000/djpbessems/ContainerImage.SpamasaurusRex/compare/v1.0.22...v1.0.23) (2024-03-11)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* Register type with gob interface ([cdbfe64](http://gitea.gitea.svc.cluster.local:3000/djpbessems/ContainerImage.SpamasaurusRex/commit/cdbfe64f5c04ac7d19ae14ca9ff826d2990dc065))
|
||||||
|
|
||||||
|
## [1.0.22](http://gitea.gitea.svc.cluster.local:3000/djpbessems/ContainerImage.SpamasaurusRex/compare/v1.0.21...v1.0.22) (2024-03-11)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* Add multiple verbose debugging ([d6148f2](http://gitea.gitea.svc.cluster.local:3000/djpbessems/ContainerImage.SpamasaurusRex/commit/d6148f289aa113f8325813e76bd039342987337a))
|
||||||
|
|
||||||
|
## [1.0.21](http://gitea.gitea.svc.cluster.local:3000/djpbessems/ContainerImage.SpamasaurusRex/compare/v1.0.20...v1.0.21) (2024-03-11)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* Add verbose debugging after session store ([1e0ddbc](http://gitea.gitea.svc.cluster.local:3000/djpbessems/ContainerImage.SpamasaurusRex/commit/1e0ddbc0eea9f97839954ac6b24c99feb4be6447))
|
||||||
|
|
||||||
|
## [1.0.20](http://gitea.gitea.svc.cluster.local:3000/djpbessems/ContainerImage.SpamasaurusRex/compare/v1.0.19...v1.0.20) (2024-03-11)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* Add more debug logging ([63f764d](http://gitea.gitea.svc.cluster.local:3000/djpbessems/ContainerImage.SpamasaurusRex/commit/63f764d1c56c5f66c15ef9cdf9139fabd4c3d8a4))
|
||||||
|
|
||||||
|
## [1.0.19](http://gitea.gitea.svc.cluster.local:3000/djpbessems/ContainerImage.SpamasaurusRex/compare/v1.0.18...v1.0.19) (2024-03-11)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* Add error handling to session store ([1af5051](http://gitea.gitea.svc.cluster.local:3000/djpbessems/ContainerImage.SpamasaurusRex/commit/1af505196ad217b91169cdac771de2ec0a35482f))
|
||||||
|
|
||||||
|
## [1.0.18](http://gitea.gitea.svc.cluster.local:3000/djpbessems/ContainerImage.SpamasaurusRex/compare/v1.0.17...v1.0.18) (2024-03-10)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* Replace incorrect http status code ([62c2730](http://gitea.gitea.svc.cluster.local:3000/djpbessems/ContainerImage.SpamasaurusRex/commit/62c27305f9ec1c922384ec8c44736414e79f8327))
|
||||||
|
|
||||||
|
## [1.0.17](http://gitea.gitea.svc.cluster.local:3000/djpbessems/ContainerImage.SpamasaurusRex/compare/v1.0.16...v1.0.17) (2024-03-10)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* Remove superfluous response write ([c293406](http://gitea.gitea.svc.cluster.local:3000/djpbessems/ContainerImage.SpamasaurusRex/commit/c29340669ce60e19aca391ac19da3b9d275f1687))
|
||||||
|
|
||||||
## [1.0.16](http://gitea.gitea.svc.cluster.local:3000/djpbessems/ContainerImage.SpamasaurusRex/compare/v1.0.15...v1.0.16) (2024-03-10)
|
## [1.0.16](http://gitea.gitea.svc.cluster.local:3000/djpbessems/ContainerImage.SpamasaurusRex/compare/v1.0.15...v1.0.16) (2024-03-10)
|
||||||
|
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"encoding/gob"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
@ -27,47 +28,11 @@ var config = oauth2.Config{
|
|||||||
Scopes: []string{"email", "openid", "profile", "user.read"},
|
Scopes: []string{"email", "openid", "profile", "user.read"},
|
||||||
}
|
}
|
||||||
|
|
||||||
var sessionStore = sessions.NewCookieStore([]byte("xDDBjhYwyndZty3exGNq2ahE8wHRCR4DfdCJCSoWXAYncfWw2UQDH63QcJ9CkrGx"))
|
var sessionStore = sessions.NewFilesystemStore("", []byte("xDDBjhYwyndZty3exGNq2ahE8wHRCR4DfdCJCSoWXAYncfWw2UQDH63QcJ9CkrGx"))
|
||||||
|
|
||||||
func rootHandler(w http.ResponseWriter, r *http.Request) {
|
func init() {
|
||||||
session, _ := sessionStore.Get(r, "spamasaurusRex")
|
// Register the oauth2.Token type with gob
|
||||||
if token, ok := session.Values["token"]; ok {
|
gob.Register(&oauth2.Token{})
|
||||||
log.Println(spew.Sdump(token))
|
|
||||||
w.Write([]byte("Token retrieved from session"))
|
|
||||||
} else {
|
|
||||||
url := config.AuthCodeURL("state", oauth2.AccessTypeOffline)
|
|
||||||
http.Redirect(w, r, url, http.StatusFound)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func callbackHandler(w http.ResponseWriter, r *http.Request) {
|
|
||||||
// Handle the callback after successful authentication
|
|
||||||
token, err := config.Exchange(r.Context(), r.URL.Query().Get("code"))
|
|
||||||
if err != nil {
|
|
||||||
if retrieveErr, ok := err.(*oauth2.RetrieveError); ok {
|
|
||||||
log.Println(retrieveErr.ErrorDescription + " (" + retrieveErr.ErrorCode + ")")
|
|
||||||
}
|
|
||||||
http.Error(w, "Error exchanging code for token", http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Store the token in the session
|
|
||||||
session, _ := sessionStore.Get(r, "spamasaurusRex")
|
|
||||||
session.Values["token"] = token
|
|
||||||
session.Save(r, w)
|
|
||||||
|
|
||||||
w.Write([]byte("Authentication successful!"))
|
|
||||||
|
|
||||||
url := "https://alias.spamasaurus.com"
|
|
||||||
http.Redirect(w, r, url, http.StatusAccepted)
|
|
||||||
}
|
|
||||||
|
|
||||||
func healthHandler(w http.ResponseWriter, r *http.Request) {
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
}
|
|
||||||
|
|
||||||
func readinessHandler(w http.ResponseWriter, r *http.Request) {
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@ -97,6 +62,64 @@ func main() {
|
|||||||
waitForShutdown(srv)
|
waitForShutdown(srv)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func rootHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
session, err := sessionStore.Get(r, "spamasaurusRex")
|
||||||
|
if err != nil {
|
||||||
|
log.Println(spew.Sdump(err))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if token, ok := session.Values["token"]; ok {
|
||||||
|
log.Println(spew.Sdump(token))
|
||||||
|
w.Write([]byte("Token retrieved from session"))
|
||||||
|
} else {
|
||||||
|
log.Println(spew.Sdump(session))
|
||||||
|
url := config.AuthCodeURL("state", oauth2.AccessTypeOffline)
|
||||||
|
http.Redirect(w, r, url, http.StatusFound)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func callbackHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
// Handle the callback after successful authentication
|
||||||
|
token, err := config.Exchange(r.Context(), r.URL.Query().Get("code"))
|
||||||
|
if err != nil {
|
||||||
|
if retrieveErr, ok := err.(*oauth2.RetrieveError); ok {
|
||||||
|
log.Println(retrieveErr.ErrorDescription + " (" + retrieveErr.ErrorCode + ")")
|
||||||
|
}
|
||||||
|
http.Error(w, "Error exchanging code for token", http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Store the token in the session
|
||||||
|
session, err := sessionStore.Get(r, "spamasaurusRex")
|
||||||
|
if err != nil {
|
||||||
|
log.Println(spew.Sdump(err))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
session.Values["token"] = token
|
||||||
|
|
||||||
|
err = session.Save(r, w)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(spew.Sdump(err))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Println(spew.Sdump(session))
|
||||||
|
|
||||||
|
// w.Write([]byte("Authentication successful!"))
|
||||||
|
|
||||||
|
url := "https://alias.spamasaurus.com"
|
||||||
|
http.Redirect(w, r, url, http.StatusSeeOther)
|
||||||
|
}
|
||||||
|
|
||||||
|
func healthHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
w.WriteHeader(http.StatusOK)
|
||||||
|
}
|
||||||
|
|
||||||
|
func readinessHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
w.WriteHeader(http.StatusOK)
|
||||||
|
}
|
||||||
|
|
||||||
func waitForShutdown(srv *http.Server) {
|
func waitForShutdown(srv *http.Server) {
|
||||||
interruptChan := make(chan os.Signal, 1)
|
interruptChan := make(chan os.Signal, 1)
|
||||||
signal.Notify(interruptChan, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)
|
signal.Notify(interruptChan, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)
|
||||||
|
Reference in New Issue
Block a user