Documentation
¶
Overview ¶
Package auth is kunveno's optional sign-in: who a person is (Identity, from a Provider), whether they may use the server (Rule), the signed session cookie, guest invitations and the /auth/ routes. It knows no provider; each lives in a package of its own (auth/yandex).
Index ¶
- Constants
- Variables
- func DisplayName(id Identity) string
- func LoadKey(path string) ([]byte, error)
- func WithIdentity(ctx context.Context, id Identity) context.Context
- type Gate
- func (g *Gate) CheckInvite(room, token string) (Invite, error)
- func (g *Gate) ExpiredSession(r *http.Request) (Identity, bool)
- func (g *Gate) ProviderInfos() []ProviderInfo
- func (g *Gate) Require(h http.Handler) http.Handler
- func (g *Gate) Routes(mux *http.ServeMux)
- func (g *Gate) SameOrigin(r *http.Request) bool
- func (g *Gate) Session(r *http.Request) (Identity, bool)
- type Identity
- type Invite
- type Invites
- func (s *Invites) Active() int
- func (s *Invites) Check(room, token string) (Invite, error)
- func (s *Invites) Create(room, createdBy string, ttl time.Duration) (string, Invite, error)
- func (s *Invites) List(room string) []Invite
- func (s *Invites) RemoveRoom(room string) ([]string, error)
- func (s *Invites) Revoke(room, id string) (Invite, error)
- func (s *Invites) Sweep() error
- type Provider
- type ProviderInfo
- type Rule
- type Sessions
Constants ¶
const ExpiredKeep = 24 * time.Hour
ExpiredKeep is how long an expired invitation is kept for its guests' reconnects to the meeting they are in: the bound on how long a meeting can outlast its link.
const LoginCookie = "__Host-kunveno-login"
LoginCookie carries the state and the return path between start and callback.
const MaxNameLen = 32
MaxNameLen matches the server's limit on participant names.
const SessionCookie = "__Host-kunveno"
SessionCookie holds a signed-in person. The __Host- prefix makes browsers insist on Secure, Path=/ and no Domain.
Variables ¶
var ErrBadInvite = errors.New("bad invite")
ErrBadInvite: the token is unknown, belongs to another room, was revoked or expired more than ExpiredKeep ago.
var ErrExpiredInvite = errors.New("expired invite")
ErrExpiredInvite: the invitation expired (less than ExpiredKeep ago) and was not revoked. It admits no new guest; the conference still lets back the guests it admitted to a meeting that is still running. Check returns the invitation with it.
Functions ¶
func DisplayName ¶
DisplayName is the name an employee has in rooms: the account's name, trimmed and cut to MaxNameLen runes, or the login's part before "@" when the account has none.
Types ¶
type Gate ¶
type Gate struct {
Providers []Provider
Rules map[string]Rule // by provider type
Sessions *Sessions
Invites *Invites
PublicURL string // https://meet.example.com, no trailing slash
Log *slog.Logger
OnSignIn func(provider, result string) // metrics; may be nil
}
Gate is the sign-in of one server: its providers, their rules, sessions and invitations.
func (*Gate) CheckInvite ¶
CheckInvite finds the usable invitation of room with token; with Session it is signal.Access.
func (*Gate) ExpiredSession ¶
ExpiredSession is the person of an intact session that expired at most one lifetime ago and whose login the rules still allow: such a person may only come back to a running meeting.
func (*Gate) ProviderInfos ¶
func (g *Gate) ProviderInfos() []ProviderInfo
func (*Gate) Require ¶
Require lets through only signed-in requests; state-changing ones must also come from our site. The handler finds the person with IdentityFrom(r.Context()).
func (*Gate) SameOrigin ¶
SameOrigin reports whether the request comes from our own pages.
type Identity ¶
type Identity struct {
Provider string // the provider's type, e.g. "yandex"
ID string // the account's permanent id at the provider
Login string // what Rule matches: for Yandex 360 organization accounts name@domain
Name string // display name from the account; may be empty
}
Identity is a person as a provider verified them.
type Invite ¶
type Invite struct {
ID string `json:"id"` // public: the dialog revokes by it
Hash string `json:"hash"` // hex SHA-256 of the token
Room string `json:"room"`
CreatedBy string `json:"created_by"`
Created time.Time `json:"created"`
Expires time.Time `json:"expires"`
Revoked bool `json:"revoked"`
}
Invite is one guest link. Hash is the SHA-256 of the token; the token itself is never kept.
type Invites ¶
Invites keeps the invitations in a JSON file (mode 0600), rewritten whole on every change.
func OpenInvites ¶
func (*Invites) Check ¶
Check finds the usable invitation of room with this token. An invitation that has expired but is still kept comes back with ErrExpiredInvite; anything else is ErrBadInvite.
func (*Invites) Create ¶
Create makes an invitation to room valid for ttl and returns its token (shown once).
func (*Invites) RemoveRoom ¶
RemoveRoom forgets every invitation of room (it was deleted, and a new room may take its slug) and returns the IDs of those that were kept, for disconnecting their guests. They are forgotten even when the file cannot be written: the error says a restart would bring them back.
type Provider ¶
type Provider interface {
Type() string // "yandex"; the path segment of /auth/<type>/
Label() string // the sign-in button's text
// AuthURL is where the browser goes to sign in; state and callback come back with the code.
AuthURL(state, callback string) string
// Exchange turns the code into a verified identity. It talks to the provider server to server.
Exchange(ctx context.Context, code, callback string) (Identity, error)
}
Provider signs people in through an OAuth 2.0 authorization code flow.
type ProviderInfo ¶
type Rule ¶
type Rule []string
Rule lists the logins a provider's accounts must match: glob patterns such as "*@example.com".
type Sessions ¶
type Sessions struct {
Now func() time.Time // time.Now; tests set it
// contains filtered or unexported fields
}
Sessions issues and reads the session cookie: base64url(JSON) "." base64url(HMAC-SHA256).
func (*Sessions) Clear ¶
func (s *Sessions) Clear(w http.ResponseWriter)
Clear removes the session cookie.
func (*Sessions) Issue ¶
func (s *Sessions) Issue(w http.ResponseWriter, id Identity)
Issue sets the session cookie for id, valid for the session lifetime. The browser keeps the cookie for one more lifetime after that, so ReadExpired can still find who it was.
func (*Sessions) Read ¶
Read returns the signed-in identity, if the cookie is present, intact and not expired.
func (*Sessions) ReadExpired ¶
ReadExpired returns the identity of an intact session that has expired, at most one session lifetime ago. It signs nobody in: the conference lets such a person back only into the meeting they were admitted to.