Skip to content

Commit

Permalink
fix session timeout
Browse files Browse the repository at this point in the history
Signed-off-by: Yuji Ito <llamerada.jp@gmail.com>
  • Loading branch information
llamerada-jp committed Jan 28, 2024
1 parent aaabace commit a23e6e2
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions seed/seed.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,7 @@ func Init(mux *http.ServeMux, secret map[string]string, rootURL, homeURL,
if err != nil {
log.Printf("failed to get session: %v", err)

session, err = store.New(r, SESSION_KEY)
if err != nil {
log.Printf("failed to renew session: %v", err)
writeErrorPage(w, 500)
return
}
session = sessions.NewSession(store, SESSION_KEY)
}

embed := map[string]any{}
Expand All @@ -118,6 +113,9 @@ func Init(mux *http.ServeMux, secret map[string]string, rootURL, homeURL,

account = session.Values["auth_type"].(string) + ":" + session.Values["user"].(string)
accountID = session.Values["user"].(string)

session.Options.MaxAge = store.Options.MaxAge
session.Save(r, w)
}

writePage(w, "main.html", map[string]any{
Expand All @@ -133,10 +131,11 @@ func Init(mux *http.ServeMux, secret map[string]string, rootURL, homeURL,
// create new state string
binaryData := make([]byte, 32)
if _, err := rand.Read(binaryData); err != nil {

log.Fatalf("failed to generate random string: %v", err)
}
state := base64.StdEncoding.EncodeToString(binaryData)
session.Values["login_github_state"] = state
session.Options.MaxAge = store.Options.MaxAge
session.Save(r, w)

url := oauth2Github.AuthCodeURL(state)
Expand Down Expand Up @@ -188,8 +187,8 @@ func Init(mux *http.ServeMux, secret map[string]string, rootURL, homeURL,
}

// recreate session
session.Options.MaxAge = -1
session = sessions.NewSession(store, SESSION_KEY)
session.Options.MaxAge = store.Options.MaxAge
session.Values["auth_type"] = "github"
session.Values["user"] = *user.Login
// session.Values["github_token"] = tok
Expand Down

0 comments on commit a23e6e2

Please sign in to comment.