Compare commits
No commits in common. "main" and "v1.0.11" have entirely different histories.
91
CHANGELOG.md
91
CHANGELOG.md
@ -1,94 +1,3 @@
|
||||
## [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)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* Change oath scopes & direct debugging to console. ([1d026d3](http://gitea.gitea.svc.cluster.local:3000/djpbessems/ContainerImage.SpamasaurusRex/commit/1d026d3ec450c94f3e0401d35f858db1627f6ef7))
|
||||
|
||||
## [1.0.15](http://gitea.gitea.svc.cluster.local:3000/djpbessems/ContainerImage.SpamasaurusRex/compare/v1.0.14...v1.0.15) (2024-03-10)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* Check for existing session w/ token ([ef817dc](http://gitea.gitea.svc.cluster.local:3000/djpbessems/ContainerImage.SpamasaurusRex/commit/ef817dc650f36d170bc254158e4a9c789cee6693))
|
||||
|
||||
## [1.0.14](http://gitea.gitea.svc.cluster.local:3000/djpbessems/ContainerImage.SpamasaurusRex/compare/v1.0.13...v1.0.14) (2024-03-10)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* Add more extensive oauth scope ([9a6e8e2](http://gitea.gitea.svc.cluster.local:3000/djpbessems/ContainerImage.SpamasaurusRex/commit/9a6e8e25f29d38dd3e66530d37445a5d5902db56))
|
||||
|
||||
## [1.0.13](http://gitea.gitea.svc.cluster.local:3000/djpbessems/ContainerImage.SpamasaurusRex/compare/v1.0.12...v1.0.13) (2024-03-10)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* Replace clientSecret value ([446999a](http://gitea.gitea.svc.cluster.local:3000/djpbessems/ContainerImage.SpamasaurusRex/commit/446999ac69b38271c15a907beaad5f25b3363d5f))
|
||||
|
||||
## [1.0.12](http://gitea.gitea.svc.cluster.local:3000/djpbessems/ContainerImage.SpamasaurusRex/compare/v1.0.11...v1.0.12) (2024-03-10)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* Add callback debugging ([774e302](http://gitea.gitea.svc.cluster.local:3000/djpbessems/ContainerImage.SpamasaurusRex/commit/774e302ce749f004e97650d05694162780e009d8))
|
||||
|
||||
## [1.0.11](http://gitea.gitea.svc.cluster.local:3000/djpbessems/ContainerImage.SpamasaurusRex/compare/v1.0.10...v1.0.11) (2024-03-10)
|
||||
|
||||
|
||||
|
4
go.mod
4
go.mod
@ -5,7 +5,6 @@ go 1.19
|
||||
require (
|
||||
github.com/breml/rootcerts v0.2.16
|
||||
github.com/gorilla/mux v1.8.1
|
||||
github.com/gorilla/sessions v1.2.2
|
||||
github.com/microsoftgraph/msgraph-sdk-go v1.34.0
|
||||
golang.org/x/oauth2 v0.18.0
|
||||
)
|
||||
@ -14,7 +13,6 @@ require (
|
||||
github.com/AzureAD/microsoft-authentication-library-for-go v1.2.1 // indirect
|
||||
github.com/golang-jwt/jwt/v5 v5.2.0 // indirect
|
||||
github.com/golang/protobuf v1.5.3 // indirect
|
||||
github.com/gorilla/securecookie v1.1.2 // indirect
|
||||
github.com/kylelemons/godebug v1.1.0 // indirect
|
||||
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c // indirect
|
||||
golang.org/x/crypto v0.21.0 // indirect
|
||||
@ -28,7 +26,7 @@ require (
|
||||
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.5.1
|
||||
github.com/Azure/azure-sdk-for-go/sdk/internal v1.5.2 // indirect
|
||||
github.com/cjlapao/common-go v0.0.39 // indirect
|
||||
github.com/davecgh/go-spew v1.1.1
|
||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
github.com/go-logr/logr v1.4.1 // indirect
|
||||
github.com/go-logr/stdr v1.2.2 // indirect
|
||||
github.com/google/uuid v1.6.0 // indirect
|
||||
|
5
go.sum
5
go.sum
@ -26,15 +26,10 @@ github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg
|
||||
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
|
||||
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
||||
github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0=
|
||||
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY=
|
||||
github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ=
|
||||
github.com/gorilla/securecookie v1.1.2 h1:YCIWL56dvtr73r6715mJs5ZvhtnY73hBvEF8kXD8ePA=
|
||||
github.com/gorilla/securecookie v1.1.2/go.mod h1:NfCASbcHqRSY+3a8tlWJwsQap2VX5pwzwo4h3eOamfo=
|
||||
github.com/gorilla/sessions v1.2.2 h1:lqzMYz6bOfvn2WriPUjNByzeXIlVzURcPmgMczkmTjY=
|
||||
github.com/gorilla/sessions v1.2.2/go.mod h1:ePLdVu+jbEgHH+KWw8I1z2wqd0BAdAQh/8LRvBeoNcQ=
|
||||
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
|
||||
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
|
||||
|
@ -2,7 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/gob"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
@ -12,9 +12,7 @@ import (
|
||||
|
||||
_ "github.com/breml/rootcerts"
|
||||
"github.com/davecgh/go-spew/spew"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/gorilla/sessions"
|
||||
|
||||
"golang.org/x/oauth2"
|
||||
"golang.org/x/oauth2/microsoft"
|
||||
@ -22,17 +20,40 @@ import (
|
||||
|
||||
var config = oauth2.Config{
|
||||
ClientID: "dccb4b93-3f75-4775-a94a-da39216d7daf",
|
||||
ClientSecret: "XN98Q~Wrp1RfakkihA1BaTKfokOSX9fuB01unanr",
|
||||
ClientSecret: "tiL8Q~qahoaZUck4ZG4sc5w.V_I.1c60bwkW6aYJ",
|
||||
Endpoint: microsoft.AzureADEndpoint("ceeae22e-f163-4ac9-b7c2-45972d3aed4f"),
|
||||
RedirectURL: "https://alias.spamasaurus.com/callback",
|
||||
Scopes: []string{"email", "openid", "profile", "user.read"},
|
||||
Scopes: []string{"User.Read"},
|
||||
}
|
||||
|
||||
var sessionStore = sessions.NewFilesystemStore("", []byte("xDDBjhYwyndZty3exGNq2ahE8wHRCR4DfdCJCSoWXAYncfWw2UQDH63QcJ9CkrGx"))
|
||||
func rootHandler(w http.ResponseWriter, r *http.Request) {
|
||||
url := config.AuthCodeURL("state", oauth2.AccessTypeOffline)
|
||||
http.Redirect(w, r, url, http.StatusFound)
|
||||
}
|
||||
|
||||
func init() {
|
||||
// Register the oauth2.Token type with gob
|
||||
gob.Register(&oauth2.Token{})
|
||||
func callbackHandler(w http.ResponseWriter, r *http.Request) {
|
||||
// Handle the callback after successful authentication
|
||||
code := r.URL.Query().Get("code")
|
||||
token, err := config.Exchange(r.Context(), code)
|
||||
if err != nil {
|
||||
http.Error(w, "Error exchanging code for token", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
// Use the token to make MS Graph queries
|
||||
// Example: Fetch user profile information
|
||||
// ...
|
||||
w.Write([]byte(spew.Sdump(token)))
|
||||
|
||||
fmt.Fprintln(w, "Authentication successful!")
|
||||
}
|
||||
|
||||
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() {
|
||||
@ -62,64 +83,6 @@ func main() {
|
||||
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) {
|
||||
interruptChan := make(chan os.Signal, 1)
|
||||
signal.Notify(interruptChan, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)
|
||||
|
Loading…
x
Reference in New Issue
Block a user