session

package
v0.0.0-...-cc1fd88 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 5, 2024 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SESSION_ACTIVE status = iota
	SESSION_INACTIVE
)
View Source
const (
	Issuer   = "kotohiro.com"
	Audience = "kotohiro.com"
)

Variables

This section is empty.

Functions

func NewExpiresAt

func NewExpiresAt() *expiresAt

func NewSessionStatus

func NewSessionStatus(num int) *status

func SetSession

func SetSession(ctx context.Context, claim *Claim) context.Context

Types

type Claim

type Claim struct {
	Sub         string  `json:"sub"` // subject (user)
	Iat         int64   `json:"iat"` // issued at (seconds)
	Exp         int64   `json:"exp"` // expiration time (seconds)
	Jti         string  `json:"jti"` // JWT ID(SessionID)
	IconURL     *string `json:"iconURL,omitempty"`
	DisplayName *string `json:"displayName,omitempty"`
	DisplayID   *string `json:"displayId,omitempty"`
	IsVerify    bool    `json:"isVerify"`
}

func GetSession

func GetSession(ctx context.Context) *Claim

func NewClaim

func NewClaim(user user.User, sessionID shared.UUID[Session]) Claim

func NewClaimFromMap

func NewClaimFromMap(claims jwt.MapClaims) Claim

func (*Claim) Audience

func (c *Claim) Audience() string

func (*Claim) ExpiresAt

func (c *Claim) ExpiresAt() time.Time

func (*Claim) GenMapClaim

func (c *Claim) GenMapClaim() *jwt.MapClaims

func (*Claim) IsExpired

func (c *Claim) IsExpired() bool

func (*Claim) IssueAt

func (c *Claim) IssueAt() time.Time

func (*Claim) Issuer

func (c *Claim) Issuer() string

func (*Claim) SessionID

func (c *Claim) SessionID() (shared.UUID[Session], error)

func (*Claim) UserID

func (c *Claim) UserID() (shared.UUID[user.User], error)

type Session

type Session struct {
	// contains filtered or unexported fields
}

func NewSession

func NewSession(
	sessionID shared.UUID[Session],
	userID shared.UUID[user.User],
	authProvider oauth.AuthProviderName,
	status status,
	expires time.Time,
	lastActivity time.Time,
) *Session

func SortByLastActivity

func SortByLastActivity(sessions []Session) []Session

func (*Session) Deactivate

func (s *Session) Deactivate()

func (*Session) ExpiresAt

func (s *Session) ExpiresAt() time.Time

func (*Session) IsActive

func (s *Session) IsActive() bool

func (*Session) LastActivityAt

func (s *Session) LastActivityAt() time.Time

func (*Session) Provider

func (s *Session) Provider() oauth.AuthProviderName

func (*Session) SessionID

func (s *Session) SessionID() shared.UUID[Session]

func (*Session) Status

func (s *Session) Status() status

func (*Session) UpdateLastActivity

func (s *Session) UpdateLastActivity()

func (*Session) UserID

func (s *Session) UserID() shared.UUID[user.User]

type SessionRepository

type SessionRepository interface {
	Create(context.Context, Session) (*Session, error)
	Update(context.Context, Session) (*Session, error)
	FindBySessionID(context.Context, shared.UUID[Session]) (*Session, error)
	FindByUserID(context.Context, shared.UUID[user.User]) ([]Session, error)
}

type SessionService

type SessionService interface {
	RefreshSession(context.Context, shared.UUID[user.User]) (*Session, error)
	DeactivateUserSessions(context.Context, shared.UUID[user.User]) error
}

type TokenManager

type TokenManager interface {
	Generate(ctx context.Context, user user.User, sessionID shared.UUID[Session]) (string, error)
	Parse(ctx context.Context, token string) (*Claim, error)
	SetSession(ctx context.Context) context.Context
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL