Help us shape the future of Go! Take the 2026 Go Developer Survey

go-tokenauth

module
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 29, 2026 License: BSD-2-Clause

README

go-tokenauth

CI Go Reference Go Report Card Go Version OpenSSF Scorecard License

Shared token validation library for SIROS AS-issued access tokens. Provides a single Go module that any service in the SIROS ecosystem can import to validate tokens, replacing per-service middleware duplication.

Packages

Package Import Description
claims github.com/sirosfoundation/go-tokenauth/claims TAC type, AccessTokenClaims, Result, AuthMode
jwks github.com/sirosfoundation/go-tokenauth/jwks JWKS fetcher with background refresh and key rotation
validator github.com/sirosfoundation/go-tokenauth/validator Dual-mode validator (asymmetric + legacy HMAC)
revocation github.com/sirosfoundation/go-tokenauth/revocation Revocation checker interface
tokengin github.com/sirosfoundation/go-tokenauth/tokengin Gin middleware (TokenAuth, MustHaveTAC)

Usage

import (
    "github.com/sirosfoundation/go-tokenauth/validator"
    "github.com/sirosfoundation/go-tokenauth/tokengin"
)

// Create validator
v := validator.New(validator.Config{
    JWKSURL:   "https://as.example.com/.well-known/jwks.json",
    Issuer:    "https://as.example.com",
    Audiences: []string{"my-service"},
    Legacy: validator.LegacyConfig{
        Enabled:    true,
        HMACSecret: []byte(os.Getenv("HMAC_SECRET")),
        Issuers:    []string{"https://as.example.com"},
    },
})
v.Start(ctx)
defer v.Stop()

// Use as Gin middleware
router.Use(tokengin.TokenAuth(v))

// Require specific permissions
router.GET("/admin", tokengin.MustHaveTAC("a"), adminHandler)

// Access validated result in handlers
func handler(c *gin.Context) {
    result, _ := tokengin.GetResult(c)
    fmt.Println(result.UserID, result.TenantID, result.TAC)
}

Development

make test       # Run tests
make lint       # Run linter
make coverage   # Generate coverage report

License

BSD 2-Clause — see LICENSE.

Directories

Path Synopsis
Package claims defines the token claim types used by the SIROS Authorization Server.
Package claims defines the token claim types used by the SIROS Authorization Server.
Package jwks provides a JWKS fetcher with background refresh for validating AS-issued access tokens.
Package jwks provides a JWKS fetcher with background refresh for validating AS-issued access tokens.
Package revocation defines the interface for token revocation checking.
Package revocation defines the interface for token revocation checking.
Package tokengin provides Gin middleware for token validation using go-tokenauth.
Package tokengin provides Gin middleware for token validation using go-tokenauth.
Package validator provides framework-agnostic token validation for both new-style asymmetric access tokens and legacy HMAC tokens.
Package validator provides framework-agnostic token validation for both new-style asymmetric access tokens and legacy HMAC tokens.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL