Documentation
¶
Overview ¶
Package authhttp connects an auth.Service to net/http.
Middleware reads a credential from the request, authenticates it and stores the auth.Principal in the request context. It accepts, in order:
- Authorization: Bearer <token>
- Authorization: DPoP <token>, with a proof of possession in the DPoP header (RFC 9449), only with WithDPoP
- Authorization: token <token> (what the gh CLI sends)
- Authorization: Basic with the token as the password (git over HTTPS), only with WithBasicPassword
- the session cookie set by SetCookie
Requests without a credential pass through anonymously; use Require or RequireScope to demand one. Requests with a header credential that does not work get a 401, and every cause of failure produces the same response. A session cookie that does not work, for example because the session was revoked or has expired, is cleared and the request passes through anonymously, so a browser holding a stale cookie can still reach the sign-in page. The service still records the rejected token.
Cookie-authenticated requests with unsafe methods must pass http.CrossOriginProtection, and only human session tokens are accepted from cookies: never agent tokens, personal access tokens, or OAuth tokens. Bearer requests are not affected by either rule. A session that Bridge started never authenticates here, from a cookie or a header.
A token bound to a key (see auth.DelegateSpec) works only with the DPoP scheme and a valid proof from its key. Sent as a Bearer token, or with a missing, invalid, replayed, or foreign proof, it fails with the same 401 as any other rejected token, and the service records the reason. A token that isn't bound is rejected with the DPoP scheme.
With WithScopesHeader, authenticated responses carry the principal's scopes in X-OAuth-Scopes, as GitHub's API does; the gh CLI reads it.
Every rejection is audited. The service records rejected tokens, and the requests that Middleware, RequireScope, and RequireFresh refuse are recorded as access_denied events, with the method and path as the action. Require and the Require functions record only behind Middleware, which tells them the service.
Index ¶
- Constants
- Variables
- func Approvable(n auth.Need, describe func(*http.Request) auth.Action) func(http.Handler) http.Handler
- func Bridge(svc *auth.Service, cfg BridgeConfig) (func(http.Handler) http.Handler, error)
- func ClearCookie(w http.ResponseWriter)
- func ClientIP(trusted ...netip.Prefix) func(*http.Request) string
- func ClientKey(addr netip.Addr) string
- func CompleteSignIn(w http.ResponseWriter, r *http.Request, svc *auth.Service, ...) (auth.Principal, error)
- func DevTools(svc *auth.Service) http.Handler
- func DeviceBound(svc *auth.Service) http.Handler
- func DeviceLabel(userAgent string) string
- func EndBridge(w http.ResponseWriter, r *http.Request, svc *auth.Service) error
- func Error(w http.ResponseWriter, r *http.Request, err error)
- func Middleware(svc *auth.Service, opts ...Option) func(http.Handler) http.Handler
- func PendingSignIn(r *http.Request, svc *auth.Service) (auth.Pending, error)
- func PreferWait(r *http.Request) time.Duration
- func Require(next http.Handler) http.Handler
- func RequireFresh(maxAge time.Duration) func(http.Handler) http.Handler
- func RequireHuman(next http.Handler) http.Handler
- func RequireNeed(n auth.Need) func(http.Handler) http.Handler
- func RequireScope(scope string) func(http.Handler) http.Handler
- func SafeReturnTo(s string) (string, bool)
- func SetCookie(w http.ResponseWriter, t auth.Token, expires time.Time)
- func SignOut(w http.ResponseWriter, r *http.Request, svc *auth.Service) error
- func StepUp(w http.ResponseWriter, r *http.Request, svc *auth.Service, ...) (auth.Principal, error)
- func WriteProblem(w http.ResponseWriter, r *http.Request, p auth.Problem)
- type AppUser
- type BridgeConfig
- type Mux
- func (m *Mux) Check() error
- func (m *Mux) Configure(opts ...Option)
- func (m *Mux) Handle(pattern string, rule Rule, h http.Handler)
- func (m *Mux) HandleFunc(pattern string, rule Rule, f func(http.ResponseWriter, *http.Request))
- func (m *Mux) Routes() []Route
- func (m *Mux) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (m *Mux) Service() *auth.Service
- type Option
- func WithAdminPrefix(prefix string) Option
- func WithApprovalURL(prefix string) Option
- func WithApprovalWait(limit time.Duration) Option
- func WithBasicPassword() Option
- func WithClientIP(trusted ...netip.Prefix) Option
- func WithClientKey(f func(*http.Request) string) Option
- func WithCrossOriginProtection(p *http.CrossOriginProtection) Option
- func WithDPoP(v *dpop.Verifier) Option
- func WithDeviceBound(prefix string, lifetime time.Duration) Option
- func WithDeviceBoundRetired(prefix string, lifetime time.Duration) Option
- func WithFreshHeader(d time.Duration) Option
- func WithLogger(l *slog.Logger) Option
- func WithOrigins(origins ...string) Option
- func WithProblemWriter(f func(http.ResponseWriter, *http.Request, auth.Problem)) Option
- func WithRealm(realm string) Option
- func WithResource(uris ...string) Option
- func WithRotation(d time.Duration) Option
- func WithScopesHeader() Option
- func WithSignInPage(signIn string, pages ...string) Option
- func WithStepUpURL(u string) Option
- type Route
- type Rule
- type SignInResult
Constants ¶
const ( ReasonAgentCookie auth.Reason = "agent_token_in_cookie" ReasonAppTokenCookie auth.Reason = "app_token_in_cookie" //nolint:gosec // G101: a reason, not a credential )
Reasons recorded when a token other than a human session token arrives in the session cookie.
const ( DeviceRegistrationHeader = "Secure-Session-Registration" DeviceResponseHeader = "Secure-Session-Response" DeviceChallengeHeader = "Secure-Session-Challenge" DeviceSessionIDHeader = "Sec-Secure-Session-Id" )
Header names of Device Bound Session Credentials (DBSC).
const ApprovalHeader = "Tensile-Approval"
ApprovalHeader carries an approval ID on an agent's retry.
const AssuranceHeader = "Tensile-Auth-Assurance"
AssuranceHeader carries the session's assurance next to FreshUntilHeader.
const BridgeCookieName = "__Host-bridge"
BridgeCookieName holds the token of the session that Bridge keeps for the application's signed-in user. The __Host- prefix makes browsers require Secure, Path=/ and no Domain attribute.
const CookieName = "__Host-session"
CookieName is the session cookie. The __Host- prefix makes browsers require Secure, Path=/ and no Domain attribute.
const DefaultBridgeMaxAge = time.Hour
DefaultBridgeMaxAge is how long a bridged session lives when BridgeConfig.MaxAge is zero.
const FreshUntilHeader = "Tensile-Auth-Fresh-Until"
FreshUntilHeader tells the browser client until when the session passes step-up checks, so it can prompt before a request instead of after a refusal. See WithFreshHeader.
const PendingCookieName = "__Host-pending"
PendingCookieName holds a pending sign-in between its first proof and the rest. Like the session cookie, it is HttpOnly, Secure, and host-only.
const ProblemContentType = "application/problem+json"
ProblemContentType is the media type of problem responses (RFC 9457).
const ReasonDPoPDisabled auth.Reason = "dpop_disabled"
ReasonDPoPDisabled is recorded for a token sent with the DPoP scheme to middleware without WithDPoP.
const ReasonDeviceExpired auth.Reason = "device_bound_expired"
ReasonDeviceExpired is recorded for a device-bound session's cookie used after its short lifetime, which its own browser would have renewed.
const ReturnToParam = "return_to"
ReturnToParam is the query parameter that carries the path a sign-in page sends the person back to after they sign in.
const ScopesHeader = "X-Oauth-Scopes"
ScopesHeader is the response header that WithScopesHeader sets.
const UnnamedAction = "authhttp.unnamed"
UnnamedAction names a need without an Action on a request that no ServeMux pattern matched. The raw path is never used, because a client controls it: "/repos//x" isn't "/repos/x", so a rule keyed on a path could be dodged.
Variables ¶
var Public = Rule{/* contains filtered or unexported fields */}
Public declares a route that anyone may call, signed in or not.
Functions ¶
func Approvable ¶
func Approvable(n auth.Need, describe func(*http.Request) auth.Action) func(http.Handler) http.Handler
Approvable is RequireNeed that turns a dead end for an agent into an approval its human can grant. A principal that meets n passes. An agent that doesn't gets the human_required problem with challenge.approval: an approval for the action that describe returns, which its human approves with one passkey tap. The agent retries the same request with the approval's ID in the Tensile-Approval header, and the route runs once if the approval is for this agent and this exact action.
A retry with the header Prefer: wait=N is held until the person decides, for at most N seconds and at most the cap from WithApprovalWait, 60 seconds by default. The refusal's fix and challenge.approval.wait_hint offer the smallest of that cap and the seconds until the approval expires, and offer no wait when the cap is 0.
n.ApprovalTTL sets how long the approval waits for the person and then for the agent, 5 minutes by default and at most 24 hours. Approvable panics when it is outside auth.MinApprovalTTL to auth.MaxApprovalTTL.
describe must return the action from the request alone, for example the method, the resource from the path, and the parameters that matter, so the retry produces the same digest. Read the body there only if the handler re-reads it from a copy.
func Bridge ¶
Bridge returns middleware that makes the application's own signed-in user a human session for the handlers it wraps, such as the oauth provider's authorization endpoint and the consent page. Use it when the application has its own login instead of the library's sign-in:
bridge, err := authhttp.Bridge(svc, authhttp.BridgeConfig{User: currentUser})
provider.Register(mux, bridge)
mux.Handle("/consent", bridge(consentPage))
The bridge keeps one short-lived session per sign-in to the application, in BridgeCookieName, and reuses it. On every request it asks User who is signed in. It reuses the session only while User reports the same user, signed in no later than the session records, with the same scopes; when the user or their scopes change, or they sign out, it revokes the session before anything else happens, so one person's application session can never approve as another. A store failure answers 503.
The session is started with auth.StartOptions.Bridged, so it is exactly as strong as the application says: it keeps the application's AuthenticatedAt, and it meets only needs that set auth.Need.Bridged, such as approving an OAuth grant. It never skips the consent page, and Middleware never accepts its token.
Requests with unsafe methods must pass http.CrossOriginProtection. The principal the bridge sets replaces any other in the request context; a request without an application user passes through unchanged.
func ClientIP ¶
ClientIP returns the client key function that WithClientIP sets, for a WithClientKey function that takes the address from somewhere else when it can verify it and falls back to this one otherwise.
func ClientKey ¶
ClientKey returns the client key that WithClientIP uses for addr: an IPv4 address, or the /64 an IPv6 address is in. An IPv4-mapped IPv6 address is keyed as IPv4.
func CompleteSignIn ¶
func CompleteSignIn(w http.ResponseWriter, r *http.Request, svc *auth.Service, proofs ...auth.Proof) (auth.Principal, error)
CompleteSignIn finishes the pending sign-in in r's pending cookie with proofs, clears that cookie, and sets the session cookie.
func DevTools ¶
DevTools serves the browser client's developer panel, under a prefix such as "/auth/dev/": GET state shows the caller's principal, POST stale makes the session look a day older, and POST recovery switches to a session in recovery mode. It answers 404 unless the service has auth.WithDevTools, which Mux.Check refuses outside localhost. Mount it behind Middleware.
func DeviceBound ¶
DeviceBound serves the DBSC endpoints under the prefix given to WithDeviceBound or WithDeviceBoundRetired: POST start binds the signed-in session to the browser's key, and POST refresh renews the cookie after a proof of it. Mount it behind Middleware, with start for signed-in sessions and refresh public: the browser refreshes after the cookie expired. In retired mode, start binds nothing and refresh moves the session back to a plain cookie.
func DeviceLabel ¶
DeviceLabel names the browser and operating system in a user agent for people, for example "Chrome on macOS" or "Safari on iPhone". It returns "Unknown device" when it recognizes neither.
func EndBridge ¶
EndBridge revokes the bridged session in r's bridge cookie, and clears the cookie. Call it from the application's sign-out handler; the bridge also revokes the session on the next request it sees without the user. Ending without a bridged session succeeds.
func Error ¶
func Error(w http.ResponseWriter, r *http.Request, err error)
Error writes the problem that auth.Describe returns for err. Use it in handlers for every error the library returns, so clients see one shape. Errors the library doesn't know become a 500 without detail; they are logged with the logger from WithLogger.
func Middleware ¶
Middleware authenticates requests with svc. See the package documentation for which credentials it accepts.
func PendingSignIn ¶
PendingSignIn returns the pending sign-in in r's pending cookie without using it up, so a second-factor page can show what's needed and verify against its first proof. It returns auth.ErrSignInIncomplete when there is none.
func PreferWait ¶
PreferWait returns the wait that r's Prefer header asks for, as "wait=<seconds>" (RFC 7240, section 4.3), at most auth.MaxApprovalWait, or 0 when it asks for none or the value isn't a positive whole number. Only the first wait preference counts.
func RequireFresh ¶
RequireFresh rejects anonymous requests with a 401 problem, and requests whose human didn't authenticate within maxAge, with a factor stronger than a recovery code, with a 403 problem whose challenge lists the factors that would pass. Agents never pass. It is RequireNeed with auth.AssuranceSingle, maxAge, and Human.
func RequireHuman ¶
RequireHuman rejects anonymous requests with a 401 problem, and agents, personal access tokens, and OAuth tokens with a 403 human_required problem.
func RequireNeed ¶
RequireNeed rejects anonymous requests with a 401 problem, and requests whose principal falls short of n with the 403 problem that auth.Service.Require describes, including its challenge. An empty n.Action becomes the ServeMux pattern that matched the request, such as "DELETE /repos/{id}", so auth.WithNeeds can tighten it per route. With another router, set n.Action: without a pattern, it becomes UnnamedAction, never the raw path. It needs Middleware, which tells it the service.
func RequireScope ¶
RequireScope rejects anonymous requests with a 401 problem and requests whose principal lacks scope with a 403 scope_missing problem.
func SafeReturnTo ¶
SafeReturnTo returns s when a sign-in page may send the browser to it after sign-in, and false for anything else. Only a path on the same origin passes: it starts with one "/", has no scheme, host, or fragment, no backslash, no space or control character, no "." or ".." segment, plain or percent-encoded, and is at most 2048 bytes. "//evil.example" and "/\evil.example" fail, because browsers read both as another host. "/.//evil.example" and "/x/..//evil.example" fail, because a URL parser removes the dot segments and leaves a path that starts with "//".
func SetCookie ¶
SetCookie stores a human session token in the session cookie. It is HttpOnly, Secure, SameSite=Lax and host-only.
func SignOut ¶
SignOut revokes the session in r's session cookie, and everything delegated from it, and clears the cookie. Signing out without a session succeeds.
func StepUp ¶
func StepUp(w http.ResponseWriter, r *http.Request, svc *auth.Service, proofs ...auth.Proof) (auth.Principal, error)
StepUp steps up the session in r's session cookie with proofs and sets the rotated token in the cookie. Other tabs keep working through the old token's grace window.
func WriteProblem ¶
WriteProblem writes p as application/problem+json with its status. It fills challenge.begin from WithStepUpURL, and sets the headers that non-browser clients read: WWW-Authenticate for a 401, an RFC 9470 insufficient_user_authentication challenge for a step-up, and Retry-After for a throttled request. Responses are never cached.
Types ¶
type AppUser ¶
type AppUser struct {
// ID is the user. Required.
ID auth.UserID
// AuthenticatedAt is when the person last signed in to the
// application, not when the application last saw them. Required:
// without it, the bridge treats the request as signed out. The
// bridge never replaces it with the current time, so a person who
// signed in long ago signs in again before approving anything that
// needs a recent sign-in, and a new sign-in, even by the same person,
// starts a new session.
AuthenticatedAt time.Time
// Scopes the bridged session holds. Approving an authorization grants
// only scopes the session holds.
Scopes []string
// Proofs are optional proofs from this sign-in, from the library's
// factor packages, such as a passkey checked with passkey.Passkeys.
// The bridge uses them only when it starts a session, and they must
// then be at most auth.MaxProofAge old. With a proof stronger than a
// federated sign-in, the session isn't [auth.Principal.BridgedOnly].
Proofs []auth.Proof
}
AppUser is the user that the application's own login signed in, as the application reports it on each request.
type BridgeConfig ¶
type BridgeConfig struct {
// User returns the application's signed-in user for r, and false when
// no one is signed in. Required. It runs on every request through
// the bridge, and must read the application's own session, never
// anything the bridge set.
User func(*http.Request) (AppUser, bool)
// MaxAge is the longest a bridged session lives. Zero means
// DefaultBridgeMaxAge. The service's policy caps it.
MaxAge time.Duration
// CrossOrigin checks requests with unsafe methods. Nil means
// http.NewCrossOriginProtection().
CrossOrigin *http.CrossOriginProtection
// Logger logs store failures. Nil logs to the service's logger, which
// auth.WithLogger sets.
Logger *slog.Logger
}
BridgeConfig configures Bridge.
type Mux ¶
type Mux struct {
// contains filtered or unexported fields
}
Mux is an http.ServeMux whose every route declares a Rule. It authenticates requests with Middleware and enforces each route's need with RequireNeed. Call Mux.Check when the server starts.
func NewMux ¶
NewMux returns a Mux for svc. opts configure Middleware, and WithAdminPrefix and WithOrigins add checks to Mux.Check.
func (*Mux) Check ¶
Check returns an error naming every misconfiguration that would weaken security, so the server can refuse to start:
- a route registered with the zero Rule
- a route under WithAdminPrefix that doesn't need a human with auth.AssuranceMulti
- no client key, from WithClientIP or WithClientKey, so every caller would share one rate-limit key
- no limiter on the service
- an origin from WithOrigins with http:// other than localhost
- a sign-in page from WithSignInPage that isn't a path on the application's origin
func (*Mux) Configure ¶
Configure adds options to the Mux's middleware, for packages that mount routes needing them, such as authroutes turning on WithDeviceBound. Call it before serving.
func (*Mux) HandleFunc ¶
HandleFunc registers f for pattern under rule.
type Option ¶
type Option func(*config)
Option configures Middleware.
func WithAdminPrefix ¶
WithAdminPrefix makes every request under prefix, for example "/admin/", need a human with auth.AssuranceMulti, whichever route serves it: a route with a host or a wildcard, such as "GET /{page}", gets the same check for admin paths. Mux.Check also refuses a route under prefix that declares a weaker rule, since the rule would mislead.
func WithApprovalURL ¶
WithApprovalURL sets the page where a human reviews an approval: the approval's ID is appended to prefix, for example "/approve/" gives "/approve/apr_…". Challenges carry the result as approval.url. A prefix that starts with "/" is joined to the first origin from WithOrigins, so the agent gets an absolute link it can show the person; the request's Host header is never used. Without this option, challenges carry the URL from auth.WithApprovalURL.
func WithApprovalWait ¶
WithApprovalWait caps how long Approvable holds an agent's retry for the person's decision, and the wait that a refusal tells the agent to ask for. A Prefer header that asks for longer waits limit. limit is cut to auth.MaxApprovalWait; 0 or less turns waiting off, and the refusal tells the agent to retry after the seconds in Retry-After instead. Without this option the cap is auth.MaxApprovalWait.
Set it below the idle timeout of every proxy in front of the application, and below the longest a request may run on the platform, for example a serverless function's limit.
func WithBasicPassword ¶
func WithBasicPassword() Option
WithBasicPassword accepts the token as the password of HTTP Basic auth, which is how git sends credentials over HTTPS. The username is ignored.
func WithClientIP ¶
WithClientIP sets the client key that the limiter and the audit log use, see auth.WithClient, to the caller's IP address: an IPv4 address, or the /64 an IPv6 address is in, since one host usually holds a whole /64. The address comes from the connection, or from X-Forwarded-For when the connection is from one of trusted, read from the right so a client can't forge it. Without this option or WithClientKey, every caller shares one rate-limit key, and Mux.Check refuses to start.
func WithClientKey ¶
WithClientKey sets the client key from f, for deployments where the key comes from somewhere else, for example a header set by a load balancer that this package can't verify.
func WithCrossOriginProtection ¶
func WithCrossOriginProtection(p *http.CrossOriginProtection) Option
WithCrossOriginProtection replaces the default http.CrossOriginProtection applied to cookie-authenticated unsafe requests, for example to add trusted origins.
func WithDPoP ¶
WithDPoP accepts tokens with the DPoP scheme, checking their proofs with v. Tokens bound to a key need it; without it, they never authenticate. Every 401 then also offers the DPoP scheme in WWW-Authenticate.
func WithDeviceBound ¶
WithDeviceBound turns on Device Bound Session Credentials (DBSC). It is off by default. After a sign-in, browsers that support it bind the session to a key in their hardware, and the session cookie then lives only lifetime (0 means auth.DefaultDeviceBoundLifetime, 10 minutes). To renew it, the browser proves the key at prefix + "/refresh", so a stolen cookie stops working within lifetime and can't be renewed elsewhere. Serve DeviceBound at prefix. Browsers without DBSC ignore it and keep a plain cookie.
To turn DBSC off after it was on, replace this option with WithDeviceBoundRetired and keep DeviceBound served. Removing both signs out every bound browser within lifetime: its refresh fails, and its short-lived cookie expires.
func WithDeviceBoundRetired ¶
WithDeviceBoundRetired turns DBSC off without signing anyone out. It binds no new sessions. A browser that bound a session earlier proves its key at prefix + "/refresh" one last time, as before, and gets a plain cookie for the session's whole lifetime and an instruction to end the device-bound session. Until then, the bound session's tokens still expire after lifetime, so a copied cookie doesn't become long-lived. Serve DeviceBound at prefix, with refresh public.
Keep it until the longest session that could have been bound has expired; after that, remove it and the route.
func WithFreshHeader ¶
WithFreshHeader sets Tensile-Auth-Fresh-Until on responses to human sessions that are fresh within d, to when that ends in RFC 3339, and Tensile-Auth-Assurance to the session's level. Use the window the app's sensitive routes use, for example 10 minutes.
func WithLogger ¶
WithLogger sets the logger for server errors, such as a store failure or an error that Error answers with 500, and for warnings, such as a token refused for its resource. The default is the logger of the service passed to Middleware or NewMux, which auth.WithLogger sets.
func WithOrigins ¶
WithOrigins lists the origins the application serves, for example "https://tensile.example". Mux.Check refuses an origin with http:// other than localhost, because passkeys and Secure cookies need https.
func WithProblemWriter ¶
WithProblemWriter replaces how problems are written, for example to wrap them in an application's own error envelope. The function must write the status and body. WriteProblem still sets WWW-Authenticate and Retry-After first.
func WithResource ¶
WithResource accepts OAuth tokens issued for the given resources (RFC 8707), such as an API that is itself a registered resource. Without it, Middleware refuses every token bound to a resource with 401, so a token a client got for an MCP server can't call the application's own API. Give the resource's URI exactly as auth.Principal.Resource holds it.
To serve an MCP server in the same process as an application that uses a Mux, route the MCP path to the MCP handler, for example one that mcpauth protects, beside the Mux rather than through it:
root := http.NewServeMux()
protector.Register(root, "/mcp", server, nil)
root.Handle("/", mux)
The Mux then still refuses MCP tokens on the application's routes. Pass the MCP resource to WithResource only when the application's own routes should accept those tokens too, within their scopes. A refusal of a token bound to a resource that WithResource doesn't list says so in its detail, and logs a warning with the resource to WithLogger.
func WithRotation ¶
WithRotation rotates a browser session's token on the first request after every interval d, for example 15 minutes, so a stolen session cookie stops working soon after its owner's next request. Only human sessions from the session cookie rotate; the old token keeps working for the service's RotateGrace, so concurrent requests from other tabs don't fail. A rotation that loses a race to another request is skipped.
func WithScopesHeader ¶
func WithScopesHeader() Option
WithScopesHeader sets the X-OAuth-Scopes response header on every authenticated request to the principal's scopes, separated by ", ". The gh CLI reads it to check a token's scopes.
func WithSignInPage ¶
WithSignInPage sets the application's sign-in page, a path on its own origin such as "/signin". With it, a signed-out person whose browser opens a page that needs a person gets a 303 redirect to that page, with the page they opened in the return_to query parameter, instead of a 401 problem. The sign-in elements read return_to and go back there after sign-in.
The redirect applies to the approval page from WithApprovalURL or auth.WithApprovalURL, and to every path in pages and under it, for example oauth.DefaultDevicePage. It applies only to GET and HEAD requests whose Accept header prefers text/html over JSON, so an API client or a fetch still gets the 401 problem. Mux.Check refuses a sign-in page that isn't a path on the application's origin.
func WithStepUpURL ¶
WithStepUpURL sets the URL that challenges name as the place to begin a step-up, for example "/auth/step-up". Clients read it from challenge.begin.
type Route ¶
type Route struct {
// Pattern is the http.ServeMux pattern, for example "DELETE /repos/{id}".
Pattern string
// Rule is what the route requires.
Rule Rule
}
Route is a route registered with a Mux.
type Rule ¶
type Rule struct {
// contains filtered or unexported fields
}
Rule declares what a Mux route requires: Public, or a need from Need. The zero Rule declares nothing, and Mux.Check refuses it.
func (Rule) Requirement ¶
Requirement returns the need r declares.
type SignInResult ¶
type SignInResult struct {
// Principal is the signed-in principal, when the sign-in completed.
Principal auth.Principal
// Needs lists the factors still required, for example [totp]. When it
// is not empty, the session cookie isn't set yet: ask for each factor,
// then call [CompleteSignIn].
Needs []auth.Method
// First is the first proof, for factors that need one, such as
// totp.TOTP.Verify.
First auth.Proof
}
SignInResult is what SignIn did.
func SignIn ¶
func SignIn(w http.ResponseWriter, r *http.Request, svc *auth.Service, first auth.Proof, o auth.StartOptions) (SignInResult, error)
SignIn starts a sign-in with a first proof, such as one from passkey.Passkeys.FinishLogin or recovery.Codes.Check. When the account needs nothing more, it starts the session and sets the session cookie. Otherwise it sets the pending cookie and returns what is still needed; finish with CompleteSignIn. o works as in auth.Service.BeginSignIn.