Documentation ¶
Index ¶
- Constants
- Variables
- func ClearUserSession(w http.ResponseWriter)
- func CreateUserSession(w http.ResponseWriter, req *http.Request, user *ent.User) *http.Request
- func GetService(ctx context.Context) *ent.Service
- func GetUser(ctx context.Context) *ent.User
- type Authorizer
- type MultiAuthenticator
- type Secret
- type ServiceAuthenticator
- type UserAuthenticator
Constants ¶
const ( SessionCookieName = "pg-session" UserCookieName = "pg-userid" HeaderService = "X-Pg-Service" HeaderSignature = "X-Pg-Signature" HeaderIdentity = "X-Pg-Identity" HeaderEpoch = "X-Pg-Epoch" )
const (
SessionTokenLength = 256
)
Variables ¶
Functions ¶
func ClearUserSession ¶
func ClearUserSession(w http.ResponseWriter)
ClearUserSession clears any user session associated with the request. It is a no-op if no user session is associated with the request.
func CreateUserSession ¶
CreateUserSession creates a new user session for a request. It adds the authenticated user to the request context and ensures session cookies are set. If user is nil, this is a no-op.
func GetService ¶
GetService from the context, returns nil for non-service contexts.
Types ¶
type Authorizer ¶
type Authorizer struct {
// contains filtered or unexported fields
}
An Authorizer asserts various properties of a requesting context.
func NewAuthorizer ¶
func NewAuthorizer() *Authorizer
NewAuthorizer initializes and returns a new authorizer.
func (*Authorizer) Authorize ¶
func (authz *Authorizer) Authorize(ctx context.Context) error
Authorize the provided context based on the preconfigured rules.
func (*Authorizer) IsActivated ¶
func (authz *Authorizer) IsActivated() *Authorizer
IsActivated ensures that authorized users are activated.
func (*Authorizer) IsAdmin ¶
func (authz *Authorizer) IsAdmin() *Authorizer
IsAdmin ensures that authorized users have admin privileges.
type MultiAuthenticator ¶
type MultiAuthenticator struct { ServiceAuth ServiceAuthenticator UserAuth UserAuthenticator }
func (MultiAuthenticator) Authenticate ¶
func (auth MultiAuthenticator) Authenticate(w http.ResponseWriter, req *http.Request) (*http.Request, error)
type Secret ¶
type Secret string
Secret returns a redacted string when displayed.
type ServiceAuthenticator ¶
ServiceAuthenticator parses http requests for service headers and adds service context to the request where possible.
func (ServiceAuthenticator) Authenticate ¶
func (auth ServiceAuthenticator) Authenticate(w http.ResponseWriter, req *http.Request) (*http.Request, error)
Authenticate a request by wrapping it's context with the authenticated service identity. It will upsert new (unactivated) service identities if the public key is not already registered. Returns an error if invalid credentials are provided.
type UserAuthenticator ¶
UserAuthenticator parses http requests for session cookies and adds user context to the request where possible.
func (UserAuthenticator) Authenticate ¶
func (auth UserAuthenticator) Authenticate(w http.ResponseWriter, req *http.Request) (*http.Request, error)
Authenticate a request by wrapping it's context with the logged in user. If no user is logged in, the original request is returned. Returns an error if it fails to find the logged in user or if invalid credentials are provided.