Documentation
¶
Index ¶
- Variables
- func GenerateJWT(userID int64, expiresIn time.Duration) (string, error)
- func GenerateURLToken(expiresIn time.Duration) (string, error)
- func InitSigningKey(ctx context.Context, database interface{ ... }) error
- func ParseJWT(tokenString string) (int64, error)
- func UserIDFromRequest(r *http.Request, authEnabled bool) int64
- func ValidateURLToken(token string) bool
- type DeviceStore
- type PendingAuth
Constants ¶
This section is empty.
Variables ¶
var SigningKey []byte
SigningKey is the HMAC-SHA256 key for JWTs. Initialized by InitSigningKey from the database.
Functions ¶
func GenerateJWT ¶
GenerateJWT creates an HS256 JWT with the given user ID and expiry.
func GenerateURLToken ¶ added in v0.2.2
GenerateURLToken creates a short-lived JWT for use as a URL query parameter.
func InitSigningKey ¶ added in v0.2.2
func InitSigningKey(ctx context.Context, database interface { GetConfig(context.Context, string) (string, error) SetConfig(context.Context, string, string) error }) error
InitSigningKey loads or generates the JWT signing key, persisted in the DB.
func UserIDFromRequest ¶
UserIDFromRequest extracts the user ID from the Authorization Bearer token. Returns 1 (default user) if auth is disabled. Returns 0 if auth is enabled and token is missing/invalid.
func ValidateURLToken ¶ added in v0.2.2
ValidateURLToken checks a token from a URL query parameter.
Types ¶
type DeviceStore ¶
type DeviceStore struct {
// contains filtered or unexported fields
}
DeviceStore manages pending device authorization requests.
func NewDeviceStore ¶
func NewDeviceStore() *DeviceStore
NewDeviceStore creates a new device authorization store.
func (*DeviceStore) Approve ¶
func (s *DeviceStore) Approve(userCode string, userID int64) bool
Approve marks a pending auth as approved with the given user ID.
func (*DeviceStore) Check ¶
func (s *DeviceStore) Check(deviceCode string) (*PendingAuth, bool)
Check returns the pending auth status for a device code.
func (*DeviceStore) NewPending ¶
func (s *DeviceStore) NewPending(expiresIn time.Duration) (deviceCode, userCode string)
NewPending creates a new pending device auth and returns device code + user code.
func (*DeviceStore) Remove ¶
func (s *DeviceStore) Remove(deviceCode string)
Remove deletes a pending auth entry.