auth

package
v0.0.0-...-9928b23 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2024 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func OauthRouter

func OauthRouter(ctx context.Context) http.Handler

Types

type APIKeyCache

type APIKeyCache struct {
	Key  string
	Role string
}

type AuthCache

type AuthCache struct {
	JWTTokenCache map[string]TokenCache
	APITokenCache map[string]APIKeyCache
}

func NewAuthCache

func NewAuthCache() *AuthCache

func (*AuthCache) CacheAPIKey

func (a *AuthCache) CacheAPIKey(key string, role string)

CacheAPIKey adds the api key to the cache

func (*AuthCache) CacheJWTToken

func (a *AuthCache) CacheJWTToken(token string, jwtToken *jwt.Token)

CacheJWTToken adds the token to the cache

func (*AuthCache) LookupCachedAPIKey

func (a *AuthCache) LookupCachedAPIKey(key string) string

LookupCachedAPIKey checks if the api key is in the cache returns the role if found, "unknown" if not found

func (*AuthCache) LookupCachedToken

func (a *AuthCache) LookupCachedToken(token string) (*jwt.Token, bool, error)

LookupCachedToken checks if the token is in the cache and returns it if it is

func (*AuthCache) TokenIsValid

func (a *AuthCache) TokenIsValid(token string) (*jwt.Token, bool, error)

TokenIsValid checks if the token is valid and returns it if it is

type InfoResponse

type InfoResponse struct {
	TenantID string `json:"tenant_id"`
	ClientID string `json:"client_id"`
}

func (*InfoResponse) Render

func (i *InfoResponse) Render(w http.ResponseWriter, r *http.Request) error

type Middleware

type Middleware struct {
	// contains filtered or unexported fields
}

func NewMiddleware

func NewMiddleware(db *sql.DB) *Middleware

func (*Middleware) APIKeyLoader

func (m *Middleware) APIKeyLoader(next http.Handler) http.Handler

APIKeyLoader middleware checks the provided api key against the database and sets the role if found

func (*Middleware) AdminOnly

func (m *Middleware) AdminOnly(next http.Handler) http.Handler

AdminOnly middleware restricts access to just administrators.

func (*Middleware) OauthLoader

func (m *Middleware) OauthLoader(next http.Handler) http.Handler

OauthLoader middleware ensures that a JWT token was passed and it's a valid token.

func (*Middleware) RoleVerifier

func (m *Middleware) RoleVerifier(next http.Handler) http.Handler

RoleVerifier middleware ensures that the Role is set and valid in context.

type OauthHandler

type OauthHandler struct {
	// contains filtered or unexported fields
}

func (*OauthHandler) Authenticate

func (h *OauthHandler) Authenticate(w http.ResponseWriter, r *http.Request)

func (*OauthHandler) Callback

func (h *OauthHandler) Callback(w http.ResponseWriter, r *http.Request)

func (*OauthHandler) GetAuthURL

func (h *OauthHandler) GetAuthURL(w http.ResponseWriter, r *http.Request)

func (*OauthHandler) Info

func (h *OauthHandler) Info(w http.ResponseWriter, r *http.Request)

type TokenCache

type TokenCache struct {
	TokenString string
	ValidUntil  int64
	Role        string
	JWTToken    *jwt.Token
}

Jump to

Keyboard shortcuts

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