Documentation
¶
Overview ¶
Package shareaccess decides who may open a portal share token.
Before #999 a share token was a bearer credential: anyone holding the URL could read the shared asset, including shares created for one named person and emailed to them. This package holds the mode domain and the access decision, independent of HTTP, so the portal's public routes all reach the same verdict through one function.
Index ¶
Constants ¶
const ( MsgSignInRequired = "This link requires you to sign in. " + "Open it again after signing in to the platform." MsgNotRecipient = "This link is restricted to the person it was shared with. " + "You are signed in as a different user. Ask the sender to share it with you." MsgRevoked = "This share link has been revoked." MsgExpired = "This share link has expired." )
Denial messages. They name the reason so a viewer can act on it (sign in, or ask the sender) instead of guessing.
Variables ¶
var ( ErrInvalidMode = errors.New( "invalid access_mode: must be restricted, authenticated, or public") ErrRestrictedNeedsRecipient = errors.New( "access_mode restricted requires shared_with_email or shared_with_user_id") )
Errors returned when a create-share request asks for an impossible mode.
Functions ¶
func Authorize ¶
Authorize decides whether viewer may open share, returning the message to render when it may not. viewer is nil for an anonymous request.
A share whose mode is empty (a row written before the mode column existed, or by a caller that left it blank) is treated as its shape's default rather than as public, so an unset value can never widen access.
func Availability ¶
Availability returns the message to render when a share cannot be opened by anyone — revoked, or past its expiry — and "" while it is still live. It is the check that precedes Authorize: who the caller is does not matter yet.
Types ¶
type Mode ¶
type Mode string
Mode determines who may open a share token.
const ( // ModeRestricted admits only the share's named recipient and its // creator. A restricted share without a recipient is invalid. ModeRestricted Mode = "restricted" // ModeAuthenticated admits any signed-in platform user. ModeAuthenticated Mode = "authenticated" // ModePublic admits anyone holding the token, without sign-in. It is // never a default: the create-share request must ask for it. ModePublic Mode = "public" )