Skip to content

Commit

Permalink
fix: gob unregistered type url
Browse files Browse the repository at this point in the history
  • Loading branch information
james-d-elliott committed Aug 26, 2023
1 parent 0fbe468 commit c888009
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 16 deletions.
10 changes: 2 additions & 8 deletions handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"encoding/json"
"fmt"
"net/http"
"net/url"

"github.com/coreos/go-oidc/v3/oidc"
"github.com/gorilla/mux"
Expand Down Expand Up @@ -63,6 +62,7 @@ func indexHandler(res http.ResponseWriter, req *http.Request) {
tpl.Claims.Email = filterText(tpl.Claims.Email, options.Filters)
tpl.Claims.Name = filterText(tpl.Claims.Name, options.Filters)
tpl.RawToken = rawTokens[tpl.Claims.JWTIdentifier]
tpl.AuthorizeCodeURL = acURLs[tpl.Claims.JWTIdentifier].String()
}

res.Header().Add("Content-Type", "text/html")
Expand Down Expand Up @@ -135,12 +135,6 @@ func protectedHandler(basic bool) http.HandlerFunc {
tpl.Vars.ProtectedSecret = fmt.Sprintf("%x", hash.Sum(nil))
}

if val, ok := session.Values["ac_url"]; ok {
if acurl, ok := val.(*url.URL); ok {
tpl.AuthorizeCodeURL = acurl.String()
}
}

res.Header().Add("Content-Type", "text/html")

if err = protectedTpl.Execute(res, tpl); err != nil {
Expand Down Expand Up @@ -234,8 +228,8 @@ func oauthCallbackHandler(res http.ResponseWriter, req *http.Request) {

session.Values["claims"] = claims
session.Values["logged"] = true
session.Values["ac_url"] = req.URL
rawTokens[claims.JWTIdentifier] = idTokenRaw
acURLs[claims.JWTIdentifier] = req.URL

if err = session.Save(req, res); err != nil {
writeErr(res, err, "unable to save session", http.StatusInternalServerError)
Expand Down
5 changes: 4 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ var store = sessions.NewCookieStore([]byte("secret-key"))

var oauth2Config oauth2.Config

var rawTokens = make(map[string]string)
var (
rawTokens = make(map[string]string)
acURLs = make(map[string]*url.URL)
)

func main() {
log.Logger = zerolog.New(zerolog.ConsoleWriter{Out: os.Stdout}).With().Timestamp().Logger().Level(zerolog.DebugLevel)
Expand Down
12 changes: 6 additions & 6 deletions templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,19 @@ var (
type indexTplData struct {
Title, Description, RawToken string

Error string
LoggedIn bool
Claims Claims
Groups []string
Error string
LoggedIn bool
Claims Claims
Groups []string
AuthorizeCodeURL string
}

type protectedTplData struct {
Title, Description string
Vars struct {
Type, Value, ProtectedSecret string
}
Claims Claims
AuthorizeCodeURL string
Claims Claims
}

type errorTplData struct {
Expand Down
1 change: 1 addition & 0 deletions templates/index.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
<p>Groups: <span id="claim-groups">{{ stringsJoin .Groups ", " }}</span></p>
<p>Name: <span id="claim-name">{{ .Claims.Name }}</span></p>
<p>Raw: <span id="raw">{{ .RawToken }}</span></p>
<p>Authorize Code URL: <span id="auth-code-url">{{ .AuthorizeCodeURL }}</span></p>
{{- else }}
<p>Not logged yet...</p> <a id="login-link" href="/login">Log in</a>
{{- end }}
Expand Down
1 change: 0 additions & 1 deletion templates/protected.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
{{- else }}
<p id="message">This is the protected invalid endpoint</p>
{{- end }}
<p id="auth-code-url">{{ .AuthorizeCodeURL }}</p>
</div>
</body>
</html>

0 comments on commit c888009

Please sign in to comment.