Documentation
¶
Overview ¶
Package mockauth is a fake auth service for the CLI's tests and the kapten-mock server. It follows the token endpoint of auth (auth/internal/oauth): every request carries a DPoP proof it verifies, device codes and refresh tokens are bound to the proof key, and refresh tokens rotate, a reused one revoking its family. Access tokens it issued can be checked with Verify, which the mock Engine does.
Index ¶
- Variables
- type Server
- func (s *Server) Approve(userCode string) bool
- func (s *Server) Close()
- func (s *Server) Count(grant string) int
- func (s *Server) ExpireAccessTokens()
- func (s *Server) RevokeSessions()
- func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (s *Server) Set(f func(*Server))
- func (s *Server) Verify(token string) error
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidToken = errors.New("the access token is invalid, expired or revoked")
ErrInvalidToken is an access token the server did not issue, or that expired or was revoked.
Functions ¶
This section is empty.
Types ¶
type Server ¶
type Server struct {
// URL is the issuer: the base URL the server is reachable at.
URL string
// Errorf reports a request the real auth would also refuse but that a
// correct CLI never sends, such as an invalid DPoP proof.
Errorf func(format string, args ...any)
// Subject, Email and Organization are put in the next issued tokens.
Subject, Email, Organization string
// OrganizationName answers GET /organizations/{Organization}.
OrganizationName string
// PendingPolls is how many polls answer authorization_pending before
// the device code is approved.
PendingPolls int
// SlowDowns is how many of those answer slow_down instead.
SlowDowns int
// Deny makes the user deny the device request.
Deny bool
// while auth restarts.
Unavailable int
// Expire makes the device code expired.
Expire bool
// ManualApproval keeps device requests pending until their code is
// approved, through Approve or the /device page.
ManualApproval bool
// Interval is the poll interval, in seconds, given with device codes.
Interval int
// TTL is the lifetime of access tokens.
TTL time.Duration
// Applications maps OAuth application client ids to their secrets.
Applications map[string]string
// ApplicationKeys maps OAuth application client ids to their public keys,
// for private_key_jwt.
ApplicationKeys map[string]jwk.Key
// OnToken runs on each token request, before it is answered.
OnToken func()
// Calls counts token requests by grant type.
Calls map[string]int
// Proofs are the jkt of every verified token request proof.
Proofs []string
// contains filtered or unexported fields
}
Server is a fake auth service. It is an http.Handler served at URL, its issuer.
func New ¶
func New() *Server
New returns a fake auth service. Set URL to where it is served before the first request.
func (*Server) ExpireAccessTokens ¶
func (s *Server) ExpireAccessTokens()
ExpireAccessTokens makes every issued access token expired, as if their lifetime had passed; refresh tokens stay valid.
func (*Server) RevokeSessions ¶
func (s *Server) RevokeSessions()
RevokeSessions revokes every grant, as when the browser session that approved them signs out: access and refresh tokens stop working.
func (*Server) ServeHTTP ¶
func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP answers auth's discovery, device, token and organization endpoints.