15 Commits

Author SHA1 Message Date
f4161b47d7 chore(release): 1.0.15 [skip ci]
## [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](ef817dc650))
2024-03-10 06:37:07 +00:00
b7e8d6ad5a Merge branch 'main' of https://code.spamasaurus.com/djpbessems/ContainerImage.SpamasaurusRex
All checks were successful
Container & Helm chart / Semantic Release (Dry-run) (push) Successful in 33s
Container & Helm chart / Helm chart (push) Successful in 17s
Container & Helm chart / Container image (push) Successful in 1m34s
Container & Helm chart / Semantic Release (push) Successful in 34s
2024-03-10 17:34:22 +11:00
ef817dc650 fix: Check for existing session w/ token 2024-03-10 17:34:20 +11:00
c33b246cf2 chore(release): 1.0.14 [skip ci]
## [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](9a6e8e25f2))
2024-03-10 06:08:38 +00:00
6d5b17515a Merge branch 'main' of https://code.spamasaurus.com/djpbessems/ContainerImage.SpamasaurusRex
All checks were successful
Container & Helm chart / Semantic Release (Dry-run) (push) Successful in 32s
Container & Helm chart / Helm chart (push) Successful in 17s
Container & Helm chart / Container image (push) Successful in 1m41s
Container & Helm chart / Semantic Release (push) Successful in 33s
2024-03-10 17:05:49 +11:00
9a6e8e25f2 fix: Add more extensive oauth scope 2024-03-10 17:05:47 +11:00
9126817665 chore(release): 1.0.13 [skip ci]
## [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](446999ac69))
2024-03-10 05:49:55 +00:00
dccca37237 Merge branch 'main' of https://code.spamasaurus.com/djpbessems/ContainerImage.SpamasaurusRex
All checks were successful
Container & Helm chart / Semantic Release (Dry-run) (push) Successful in 34s
Container & Helm chart / Helm chart (push) Successful in 17s
Container & Helm chart / Container image (push) Successful in 1m43s
Container & Helm chart / Semantic Release (push) Successful in 32s
2024-03-10 16:47:01 +11:00
446999ac69 fix: Replace clientSecret value 2024-03-10 16:46:59 +11:00
b1f6a4666c chore(release): 1.0.12 [skip ci]
## [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](774e302ce7))
2024-03-10 05:40:08 +00:00
fdf1501152 Merge branch 'main' of https://code.spamasaurus.com/djpbessems/ContainerImage.SpamasaurusRex
All checks were successful
Container & Helm chart / Semantic Release (Dry-run) (push) Successful in 31s
Container & Helm chart / Helm chart (push) Successful in 16s
Container & Helm chart / Container image (push) Successful in 1m40s
Container & Helm chart / Semantic Release (push) Successful in 32s
2024-03-10 16:37:19 +11:00
774e302ce7 fix: Add callback debugging 2024-03-10 16:37:17 +11:00
f5f3b38299 chore(release): 1.0.11 [skip ci]
## [1.0.11](http://gitea.gitea.svc.cluster.local:3000/djpbessems/ContainerImage.SpamasaurusRex/compare/v1.0.10...v1.0.11) (2024-03-10)

### Bug Fixes

* Remove redundant slash character ([7b69a76](7b69a765e2))
2024-03-10 05:25:56 +00:00
09dabc1c18 Merge branch 'main' of https://code.spamasaurus.com/djpbessems/ContainerImage.SpamasaurusRex
All checks were successful
Container & Helm chart / Semantic Release (Dry-run) (push) Successful in 42s
Container & Helm chart / Helm chart (push) Successful in 23s
Container & Helm chart / Container image (push) Successful in 1m51s
Container & Helm chart / Semantic Release (push) Successful in 40s
2024-03-10 16:22:43 +11:00
7b69a765e2 fix: Remove redundant slash character 2024-03-10 16:22:41 +11:00
4 changed files with 66 additions and 11 deletions

View File

@ -1,3 +1,38 @@
## [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)
### Bug Fixes
* Remove redundant slash character ([7b69a76](http://gitea.gitea.svc.cluster.local:3000/djpbessems/ContainerImage.SpamasaurusRex/commit/7b69a765e2b8371a285999360721df81abee74c9))
## [1.0.10](http://gitea.gitea.svc.cluster.local:3000/djpbessems/ContainerImage.SpamasaurusRex/compare/v1.0.9...v1.0.10) (2024-03-10)

2
go.mod
View File

@ -13,6 +13,8 @@ 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/gorilla/sessions v1.2.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

4
go.sum
View File

@ -30,6 +30,10 @@ 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=

View File

@ -12,7 +12,9 @@ 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"
@ -20,32 +22,44 @@ import (
var config = oauth2.Config{
ClientID: "dccb4b93-3f75-4775-a94a-da39216d7daf",
ClientSecret: "tiL8Q~qahoaZUck4ZG4sc5w.V_I.1c60bwkW6aYJ",
ClientSecret: "XN98Q~Wrp1RfakkihA1BaTKfokOSX9fuB01unanr",
Endpoint: microsoft.AzureADEndpoint("ceeae22e-f163-4ac9-b7c2-45972d3aed4f"),
RedirectURL: "https://alias.spamasaurus.com//callback",
Scopes: []string{"User.Read"},
RedirectURL: "https://alias.spamasaurus.com/callback",
Scopes: []string{"User.Read", "Profile"},
}
var sessionStore = sessions.NewCookieStore([]byte("xDDBjhYwyndZty3exGNq2ahE8wHRCR4DfdCJCSoWXAYncfWw2UQDH63QcJ9CkrGx"))
func rootHandler(w http.ResponseWriter, r *http.Request) {
url := config.AuthCodeURL("state", oauth2.AccessTypeOffline)
http.Redirect(w, r, url, http.StatusFound)
session, _ := sessionStore.Get(r, "spamasaurusRex")
if token, ok := session.Values["token"]; ok {
w.Write([]byte(spew.Sdump(token)))
} 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
code := r.URL.Query().Get("code")
token, err := config.Exchange(r.Context(), code)
token, err := config.Exchange(r.Context(), r.URL.Query().Get("code"))
if err != nil {
if retrieveErr, ok := err.(*oauth2.RetrieveError); ok {
w.Write([]byte(retrieveErr.ErrorDescription + " (" + retrieveErr.ErrorCode + ")"))
}
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)))
// Store the token in the session
session, _ := sessionStore.Get(r, "spamasaurusRex")
session.Values["token"] = token
session.Save(r, w)
fmt.Fprintln(w, "Authentication successful!")
url := "https://alias.spamasaurus.com"
http.Redirect(w, r, url, http.StatusAccepted)
}
func healthHandler(w http.ResponseWriter, r *http.Request) {