mirror of
https://github.com/AdguardTeam/AdGuardHome.git
synced 2025-10-26 11:27:18 +00:00
Merge in DNS/adguard-home from AGDNS-2743-auth-middleware to master
Squashed commit of the following:
commit 3d0621f1992fd42ecdf3f5b1039d938db065e478
Merge: 320581ba7 57dc791f5
Author: Stanislav Chzhen <s.chzhen@adguard.com>
Date: Fri May 30 16:38:22 2025 +0300
Merge branch 'master' into AGDNS-2743-auth-middleware
commit 320581ba7693183a39c53dc9f71180ab2a4f4d88
Author: Stanislav Chzhen <s.chzhen@adguard.com>
Date: Thu May 29 21:39:13 2025 +0300
all: imp code
commit 4de3e7e9baa4459ce0c18d229c809dedeb59a590
Author: Stanislav Chzhen <s.chzhen@adguard.com>
Date: Thu May 29 17:46:51 2025 +0300
home: imp tests
commit 6556aa48e77bd11254f097a888c51b6c5cd931b9
Author: Stanislav Chzhen <s.chzhen@adguard.com>
Date: Wed May 28 22:53:01 2025 +0300
all: add tests
commit 338eea6699bd2f3ae654c2f1f65fe44f43f4b1dd
Author: Stanislav Chzhen <s.chzhen@adguard.com>
Date: Tue May 27 15:53:31 2025 +0300
home: ctx key web user
commit 0453e5a9717954308331ea1aff2e43257c0f5569
Author: Stanislav Chzhen <s.chzhen@adguard.com>
Date: Thu May 22 14:28:09 2025 +0300
home: auth mw
39 lines
964 B
Go
39 lines
964 B
Go
package aghuser
|
|
|
|
import (
|
|
"crypto/rand"
|
|
"time"
|
|
)
|
|
|
|
// SessionTokenLength is the length of the web user session token.
|
|
const SessionTokenLength = 16
|
|
|
|
// SessionToken is the type for the web user session token.
|
|
type SessionToken [SessionTokenLength]byte
|
|
|
|
// NewSessionToken returns a cryptographically secure randomly generated web
|
|
// user session token. If an error occurs during random generation, it will
|
|
// cause the program to crash.
|
|
func NewSessionToken() (t SessionToken) {
|
|
_, _ = rand.Read(t[:])
|
|
|
|
return t
|
|
}
|
|
|
|
// Session represents a web user session.
|
|
type Session struct {
|
|
// Expire indicates when the session will expire.
|
|
Expire time.Time
|
|
|
|
// UserLogin is the login of the web user associated with the session.
|
|
//
|
|
// TODO(s.chzhen): Remove this field and associate the user by UserID.
|
|
UserLogin Login
|
|
|
|
// Token is the session token.
|
|
Token SessionToken
|
|
|
|
// UserID is the identifier of the web user associated with the session.
|
|
UserID UserID
|
|
}
|