MCPcopy Create free account
hub / github.com/PerpetualSoftware/pad / createAuthSession

Method createAuthSession

internal/server/handlers_auth.go:331–352  ·  view source on GitHub ↗
(w http.ResponseWriter, r *http.Request, user *models.User, ttl time.Duration)

Source from the content-addressed store, hash-verified

329}
330
331func (s *Server) createAuthSession(w http.ResponseWriter, r *http.Request, user *models.User, ttl time.Duration) (string, error) {
332 token, err := s.store.CreateSession(user.ID, "web", clientIP(r), r.UserAgent(), ttl)
333 if err != nil {
334 writeError(w, http.StatusInternalServerError, "internal_error", "Failed to create session")
335 return "", err
336 }
337
338 http.SetCookie(w, &http.Cookie{
339 Name: sessionCookieName(s.secureCookies),
340 Value: token,
341 Path: "/",
342 MaxAge: int(ttl.Seconds()),
343 HttpOnly: true,
344 Secure: s.secureCookies,
345 SameSite: http.SameSiteLaxMode,
346 })
347
348 // Set CSRF cookie alongside the session cookie
349 setCSRFCookie(w, int(ttl.Seconds()), s.secureCookies)
350
351 return token, nil
352}
353
354// handleBootstrap creates the first admin account for a fresh instance.
355//

Callers 5

handleBootstrapMethod · 0.95
handleRegisterMethod · 0.95
handleLoginMethod · 0.95
handleTOTPLoginVerifyMethod · 0.95
handleOAuthLoginMethod · 0.95

Calls 5

clientIPFunction · 0.85
writeErrorFunction · 0.85
sessionCookieNameFunction · 0.85
setCSRFCookieFunction · 0.85
CreateSessionMethod · 0.80

Tested by

no test coverage detected