(c *gin.Context)
| 403 | } |
| 404 | |
| 405 | func (auth *AuthService) GetSessionCookie(c *gin.Context) (repository.Session, error) { |
| 406 | cookie, err := c.Cookie(auth.config.SessionCookieName) |
| 407 | |
| 408 | if err != nil { |
| 409 | return repository.Session{}, err |
| 410 | } |
| 411 | |
| 412 | session, err := auth.queries.GetSession(c, cookie) |
| 413 | |
| 414 | if err != nil { |
| 415 | if errors.Is(err, sql.ErrNoRows) { |
| 416 | return repository.Session{}, fmt.Errorf("session not found") |
| 417 | } |
| 418 | return repository.Session{}, err |
| 419 | } |
| 420 | |
| 421 | currentTime := time.Now().Unix() |
| 422 | |
| 423 | if auth.config.SessionMaxLifetime != 0 && session.CreatedAt != 0 { |
| 424 | if currentTime-session.CreatedAt > int64(auth.config.SessionMaxLifetime) { |
| 425 | err = auth.queries.DeleteSession(c, cookie) |
| 426 | if err != nil { |
| 427 | tlog.App.Error().Err(err).Msg("Failed to delete session exceeding max lifetime") |
| 428 | } |
| 429 | return repository.Session{}, fmt.Errorf("session expired due to max lifetime exceeded") |
| 430 | } |
| 431 | } |
| 432 | |
| 433 | if currentTime > session.Expiry { |
| 434 | err = auth.queries.DeleteSession(c, cookie) |
| 435 | if err != nil { |
| 436 | tlog.App.Error().Err(err).Msg("Failed to delete expired session") |
| 437 | } |
| 438 | return repository.Session{}, fmt.Errorf("session expired") |
| 439 | } |
| 440 | |
| 441 | return repository.Session{ |
| 442 | UUID: session.UUID, |
| 443 | Username: session.Username, |
| 444 | Email: session.Email, |
| 445 | Name: session.Name, |
| 446 | Provider: session.Provider, |
| 447 | TotpPending: session.TotpPending, |
| 448 | OAuthGroups: session.OAuthGroups, |
| 449 | OAuthName: session.OAuthName, |
| 450 | OAuthSub: session.OAuthSub, |
| 451 | }, nil |
| 452 | } |
| 453 | |
| 454 | func (auth *AuthService) LocalAuthConfigured() bool { |
| 455 | return len(auth.config.Users) > 0 |
no test coverage detected