Documentation ¶
Index ¶
- Constants
- func FromCtx(ctx context.Context) *zap.Logger
- func Get() *zap.Logger
- func GetClaims(ctx context.Context, token Token) error
- func TokenHasRequiredRoles(tokenRoles []string, requiredRoles []string) bool
- func TokenHasRequiredScopes(tokenScopes []string, requiredScopes []string) bool
- type AuthenticationType
- type CookieOptions
- type DefaultFilter
- type Filter
- type JwkAuthOptions
- func (options *JwkAuthOptions) AuthMiddleware(filter ...Filter) func(next http.Handler) http.Handler
- func (options *JwkAuthOptions) WithCookieOptions(cookieOptions CookieOptions) *JwkAuthOptions
- func (options *JwkAuthOptions) WithCreateToken(createToken func(claims map[string]interface{}) (Token, error)) *JwkAuthOptions
- func (options *JwkAuthOptions) WithFilter(filter Filter) *JwkAuthOptions
- func (options *JwkAuthOptions) WithIssuer(issuer string) *JwkAuthOptions
- func (options *JwkAuthOptions) WithIssuerJwkUrl(issuerJwkUrl string) *JwkAuthOptions
- type TestServer
- type Token
Constants ¶
const JwtTokenKey = "jwt-token"
JwtTokenKey is the key for the jwt token in the context.
const LogCtxKey = "log"
Variables ¶
This section is empty.
Functions ¶
func TokenHasRequiredRoles ¶ added in v0.3.0
TokenHasRequiredRoles checks if the token has the required scopes.
func TokenHasRequiredScopes ¶ added in v0.3.0
TokenHasRequiredScopes checks if the token has the required scopes.
Types ¶
type AuthenticationType ¶ added in v0.5.0
type AuthenticationType int
type CookieOptions ¶ added in v0.5.0
type CookieOptions struct {
Name string
}
type DefaultFilter ¶ added in v0.4.0
func (DefaultFilter) Roles ¶ added in v0.4.0
func (f DefaultFilter) Roles() []string
func (DefaultFilter) Scopes ¶ added in v0.4.0
func (f DefaultFilter) Scopes() []string
type JwkAuthOptions ¶
type JwkAuthOptions struct { CookieOptions CookieOptions JwkSet jwk.Set Issuer string IssuerJwkUrl string Filter Filter CreateToken func(claims map[string]interface{}) (Token, error) }
JwkAuthOptions is the struct for the jwk auth middleware.
func NewJwkOptions ¶
func NewJwkOptions(issuer string, jwksUrl string) (*JwkAuthOptions, error)
NewJwkOptions creates a new jwk auth middleware.
func (*JwkAuthOptions) AuthMiddleware ¶
func (options *JwkAuthOptions) AuthMiddleware(filter ...Filter) func(next http.Handler) http.Handler
AuthMiddleware is the middleware for authenticating requests.
func (*JwkAuthOptions) WithCookieOptions ¶ added in v0.5.0
func (options *JwkAuthOptions) WithCookieOptions(cookieOptions CookieOptions) *JwkAuthOptions
WithCookieOptions sets the cookie options that determines how the cookie is extracted from the request.
func (*JwkAuthOptions) WithCreateToken ¶ added in v0.3.2
func (options *JwkAuthOptions) WithCreateToken(createToken func(claims map[string]interface{}) (Token, error)) *JwkAuthOptions
WithCreateToken sets the create token option that determines how the token is created.
func (*JwkAuthOptions) WithFilter ¶ added in v0.3.0
func (options *JwkAuthOptions) WithFilter(filter Filter) *JwkAuthOptions
WithFilter sets the filter option that determines the roles and scopes that are required for the token.
func (*JwkAuthOptions) WithIssuer ¶ added in v0.2.0
func (options *JwkAuthOptions) WithIssuer(issuer string) *JwkAuthOptions
WithIssuer sets the issuer option that determines the issuer of the tokens.
func (*JwkAuthOptions) WithIssuerJwkUrl ¶ added in v0.2.0
func (options *JwkAuthOptions) WithIssuerJwkUrl(issuerJwkUrl string) *JwkAuthOptions
WithIssuerJwkUrl sets the issuer JWK URL option that determines where the JWK Set should be fetched from.
type TestServer ¶
type TestServer struct { JwkSet jwk.Set PrivateKey *rsa.PrivateKey Issuer string Server *http.Server Kid string }
func NewTestServer ¶
func NewTestServer(addr string) (*TestServer, error)
NewTestServer creates a new test server with a JWK Set and RSA key pair. The server will listen on the specified address. If no address is specified, the server will listen on a random port. The server can be stopped by calling the Stop method.
The JWK Set will contain a single JWK with the following properties: - Key ID: test-kid - Algorithm: RS256 - Key Usage: Signature - Key Type: RSA
The RSA key pair will be used to sign JWTs.
The Issuer property will be set to the address of the server.
The Kid property will be set to the Key ID of the JWK.
The server will have one endpoint: - /keys: Returns the JWK Set
func (*TestServer) IssueToken ¶
func (s *TestServer) IssueToken(claims any) (string, error)
IssueToken issues a JWT with the specified claims. The token will be signed with the RSA key pair.
The token will have the following claims: - Audience: test-audience - Issuer: The address of the test server - Subject: test-subject - Not Before: The current time - Issued At: The current time - Expiration: The current time plus one minute - JWT ID: test-token-id
func (*TestServer) Stop ¶
func (s *TestServer) Stop(ctx context.Context)
Stop stops the test server.