Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhanced auth token / remember me #27606

Merged
merged 12 commits into from
Oct 14, 2023
Prev Previous commit
Next Next commit
Add migration.
  • Loading branch information
KN4CK3R committed Aug 3, 2023
commit c47e8c9d867289b3972d0f8b64026b94d6970f29
2 changes: 1 addition & 1 deletion models/auth/auth_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (

var ErrAuthTokenNotExist = util.NewNotExistErrorf("auth token does not exist")

type AuthToken struct {
type AuthToken struct { //nolint:revive
ID string `xorm:"pk"`
TokenHash string
UserID int64 `xorm:"INDEX"`
Expand Down
2 changes: 2 additions & 0 deletions models/migrations/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,8 @@ var migrations = []Migration{
NewMigration("Drop deleted branch table", v1_21.DropDeletedBranchTable),
// v270 -> v271
NewMigration("Fix PackageProperty typo", v1_21.FixPackagePropertyTypo),
// v271 -> v272
NewMigration("Add auth_token table", v1_21.CreateAuthTokenTable),
}

// GetCurrentDBVersion returns the current db version
Expand Down
21 changes: 21 additions & 0 deletions models/migrations/v1_21/v271.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright 2023 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT

package v1_21 //nolint

import (
"code.gitea.io/gitea/modules/timeutil"

"xorm.io/xorm"
)

func CreateAuthTokenTable(x *xorm.Engine) error {
type AuthToken struct {
ID string `xorm:"pk"`
TokenHash string
UserID int64 `xorm:"INDEX"`
ExpiresUnix timeutil.TimeStamp
}

return x.Sync(new(AuthToken))
}
2 changes: 2 additions & 0 deletions services/auth/auth_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import (
"code.gitea.io/gitea/modules/util"
)

// Based on https://paragonie.com/blog/2015/04/secure-authentication-php-with-long-term-persistence#secure-remember-me-cookies

var (
ErrAuthTokenInvalidFormat = util.NewInvalidArgumentErrorf("auth token has an invalid format")
ErrAuthTokenExpired = util.NewInvalidArgumentErrorf("auth token has expired")
Expand Down