pat.go
pat.go - Overview
-
Overview This file defines a middleware
Pat
that authenticates HTTP requests using Personal Access Tokens (PATs). It retrieves the PAT from the request headers, validates it against the database, and if valid, populates the request context with user claims. -
Detailed Documentation
Type: Pat
- Purpose: Represents the Personal Access Token middleware.
- Fields:
store
(sqlstore.SQLStore): SQLStore instance for database operations.uuid
(*authtypes.UUID): UUID generator and extractor.headers
([]string): List of HTTP headers to check for the PAT.
Function: NewPat
- Purpose: Creates a new
Pat
middleware instance. - Parameters:
store
(sqlstore.SQLStore): The SQLStore instance.headers
([]string): List of HTTP headers where PAT might be present.
- Returns:
*Pat
: A pointer to the newPat
instance.
Function: Wrap
- Purpose: Wraps an
http.Handler
with the PAT authentication middleware. - Parameters:
next
(http.Handler): The next handler in the chain.
- Returns:
http.Handler
: Anhttp.Handler
that performs PAT authentication before calling the next handler.
- Detailed Documentation:
- It extracts the PAT from the request headers.
- It retrieves the PAT information from the database.
- It validates the PAT's expiration and revocation status.
- If the PAT is valid, it retrieves the associated user information.
- It creates a JWT claim and adds it to the request context.
- It updates the
LastUsed
timestamp of the PAT in the database.
-
Code Examples None
-
Clarity and Accuracy The documentation is derived directly from the code.
-
Markdown & MDX Perfection The markdown is formatted correctly.
-
Edge Cases To Avoid Breaking MDX All potential MDX breaking patterns are avoided.
-
Getting Started Relevance Include in Getting Started: NO