MCPcopy
hub / github.com/tinyauthapp/tinyauth / CreateSessionCookie

Method CreateSessionCookie

internal/service/auth_service.go:295–333  ·  view source on GitHub ↗
(c *gin.Context, data *repository.Session)

Source from the content-addressed store, hash-verified

293}
294
295func (auth *AuthService) CreateSessionCookie(c *gin.Context, data *repository.Session) error {
296 uuid, err := uuid.NewRandom()
297
298 if err != nil {
299 return err
300 }
301
302 var expiry int
303
304 if data.TotpPending {
305 expiry = 3600
306 } else {
307 expiry = auth.config.SessionExpiry
308 }
309
310 session := repository.CreateSessionParams{
311 UUID: uuid.String(),
312 Username: data.Username,
313 Email: data.Email,
314 Name: data.Name,
315 Provider: data.Provider,
316 TotpPending: data.TotpPending,
317 OAuthGroups: data.OAuthGroups,
318 Expiry: time.Now().Add(time.Duration(expiry) * time.Second).Unix(),
319 CreatedAt: time.Now().Unix(),
320 OAuthName: data.OAuthName,
321 OAuthSub: data.OAuthSub,
322 }
323
324 _, err = auth.queries.CreateSession(c, session)
325
326 if err != nil {
327 return err
328 }
329
330 c.SetCookie(auth.config.SessionCookieName, session.UUID, expiry, "/", fmt.Sprintf(".%s", auth.config.CookieDomain), auth.config.SecureCookie, true)
331
332 return nil
333}
334
335func (auth *AuthService) RefreshSessionCookie(c *gin.Context) error {
336 cookie, err := c.Cookie(auth.config.SessionCookieName)

Callers 3

oauthCallbackHandlerMethod · 0.80
loginHandlerMethod · 0.80
totpHandlerMethod · 0.80

Calls 2

CreateSessionMethod · 0.80
NewRandomMethod · 0.65

Tested by

no test coverage detected