Back to godoc.org

Package session

v0.0.0-...-7732e28
Latest Go to latest

The highest tagged major version is .

Published: 1 day ago | License: AGPL-3.0 | Module: github.com/cozy/cozy-stack

Index

Constants

const SessionMaxAge = 30 * 24 * time.Hour

SessionMaxAge is the maximum duration of the session in seconds

Variables

var (
	// ErrNoCookie is returned by GetSession if there is no cookie
	ErrNoCookie = errors.New("No session cookie")
	// ErrExpired is returned when the session has expired
	ErrExpired = errors.New("Session expired")
	// ErrInvalidID is returned by GetSession if the cookie contains wrong ID
	ErrInvalidID = errors.New("Session cookie has wrong ID")
)

func CheckDelegatedJWT

func CheckDelegatedJWT(instance *instance.Instance, token string) error

CheckDelegatedJWT checks if a delegated JWT is valid for a given instance

func CookieDomain

func CookieDomain(i *instance.Instance) string

CookieDomain returns the domain on which the cookie will be set. On nested subdomains, the cookie is put on the domain of the instance, but for flat subdomains, we need to put it one level higher (eg .mycozy.cloud instead of .example.mycozy.cloud) to make the cookie available when the user visits their apps.

func CookieName

func CookieName(i *instance.Instance) string

CookieName returns the name of the cookie used for the given instance.

func DeleteOthers

func DeleteOthers(i *instance.Instance, selfSessionID string) error

DeleteOthers will remove all sessions except the one given in parameter.

func PushLoginRegistration

func PushLoginRegistration(db prefixer.Prefixer, login *LoginEntry, clientID string) error

PushLoginRegistration pushes a new login into the registration queue.

func RemoveLoginRegistration

func RemoveLoginRegistration(domain, clientID string) error

RemoveLoginRegistration removes a login from the registration map.

func SendNewRegistrationNotification

func SendNewRegistrationNotification(i *instance.Instance, clientRegistrationID string) error

SendNewRegistrationNotification is used to send a notification to the user when a new OAuth client is registered.

func StoreNewLoginEntry

func StoreNewLoginEntry(i *instance.Instance, sessionID, clientID string, req *http.Request, notifEnabled bool) error

StoreNewLoginEntry creates a new login entry in the database associated with the given instance.

func SweepLoginRegistrations

func SweepLoginRegistrations() utils.Shutdowner

SweepLoginRegistrations starts the login registration process.

This process involving a queue of registration login entries is necessary to distinguish "normal" logins from logins to give right to an OAuth application.

Since we cannot really distinguish between them other than trusting the user, we send a notification to the user by following this process:

- if we identify a login for a device registration — by looking at the
  redirection address — we push an entry onto the queue
- if we do not receive the activation of the device by the user in 5
  minutes, we send a notification for a "normal" login
- otherwise we send a notification for the activation of a new device.

type ExternalClaims

type ExternalClaims struct {
	jwt.StandardClaims
	Name  string `json:"name"`
	Code  string `json:"code"`
	Email string `json:"email,omitempty"`
	UUID  string `json:"uuid,omitempty"`
}

ExternalClaims is the format for JWT for authentication from external sources

type LoginEntry

type LoginEntry struct {
	DocID       string `json:"_id,omitempty"`
	DocRev      string `json:"_rev,omitempty"`
	SessionID   string `json:"session_id"`
	IP          string `json:"ip"`
	City        string `json:"city,omitempty"`
	Subdivision string `json:"subdivision,omitempty"`
	Country     string `json:"country,omitempty"`
	// XXX No omitempty on os and browser, because they are indexed in couchdb
	UA                 string    `json:"user_agent"`
	OS                 string    `json:"os"`
	Browser            string    `json:"browser"`
	ClientRegistration bool      `json:"client_registration"`
	CreatedAt          time.Time `json:"created_at"`
}

LoginEntry stores informations associated with a new login. It is useful to provide the user with informations about the history of all the logins that may have happened on its domain.

func (*LoginEntry) Clone

func (l *LoginEntry) Clone() couchdb.Doc

Clone implements couchdb.Doc

func (*LoginEntry) DocType

func (l *LoginEntry) DocType() string

DocType implements couchdb.Doc

func (*LoginEntry) ID

func (l *LoginEntry) ID() string

ID implements couchdb.Doc

func (*LoginEntry) Rev

func (l *LoginEntry) Rev() string

Rev implements couchdb.Doc

func (*LoginEntry) SetID

func (l *LoginEntry) SetID(v string)

SetID implements couchdb.Doc

func (*LoginEntry) SetRev

func (l *LoginEntry) SetRev(v string)

SetRev implements couchdb.Doc

type Session

type Session struct {
	DocID     string    `json:"_id,omitempty"`
	DocRev    string    `json:"_rev,omitempty"`
	CreatedAt time.Time `json:"created_at"`
	LastSeen  time.Time `json:"last_seen"`
	LongRun   bool      `json:"long_run"`
	// contains filtered or unexported fields
}

A Session is an instance opened in a browser

func FromCookie

func FromCookie(c echo.Context, i *instance.Instance) (*Session, error)

FromCookie retrieves the session from a echo.Context cookies.

func Get

func Get(i *instance.Instance, sessionID string) (*Session, error)

Get fetches the session

func GetAll

func GetAll(inst *instance.Instance) ([]*Session, error)

GetAll returns all the active sessions

func New

func New(i *instance.Instance, longRun bool) (*Session, error)

New creates a session in couchdb for the given instance

func (*Session) Clone

func (s *Session) Clone() couchdb.Doc

Clone implements couchdb.Doc

func (*Session) Delete

func (s *Session) Delete(i *instance.Instance) *http.Cookie

Delete is a function to delete the session in couchdb, and returns a cookie with a negative MaxAge to clear it

func (*Session) DocType

func (s *Session) DocType() string

DocType implements couchdb.Doc

func (*Session) ID

func (s *Session) ID() string

ID implements couchdb.Doc

func (*Session) OlderThan

func (s *Session) OlderThan(t time.Duration) bool

OlderThan checks if a session last seen is older than t from now

func (*Session) Rev

func (s *Session) Rev() string

Rev implements couchdb.Doc

func (*Session) SetID

func (s *Session) SetID(v string)

SetID implements couchdb.Doc

func (*Session) SetRev

func (s *Session) SetRev(v string)

SetRev implements couchdb.Doc

func (*Session) ToCookie

func (s *Session) ToCookie() (*http.Cookie, error)

ToCookie returns an http.Cookie for this Session

Package Files

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier