replace_token

package module
v0.0.0-...-ccab99e Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2024 License: MIT Imports: 13 Imported by: 0

README

Caddy replace_token

A Caddy v2 plugin that fetches a temporary token and replaces the original one in requests.

Features

This plugin implements the http.handlers module, which:

  • Uses the bearer token from request to fetch a temporary token from specified authentication server.

  • Replaces the original token in request header, and pass to following handlers.

  • Caches temporary tokens in memory and (optional) local storage.

Configuration

{
    "handler": "replace_token",
    "auth_url": "",
    "headers": {
        "": ""
    },
    "cache_file": ""
}

headers sets the headers of request to authentication server.

The authentication server should return a token and unix timestamp expire_at in the response body if succeeds.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthResponse

type AuthResponse struct {
	Token     string `json:"token"`
	ExpiresAt int64  `json:"expires_at"`
}

type ReplaceToken

type ReplaceToken struct {
	AuthURL      string      `json:"auth_url,omitempty"`
	DefaultToken string      `json:"default_token,omitempty"`
	Headers      http.Header `json:"headers"`
	CacheFile    string      `json:"cache_file,omitempty"`

	Cache  map[string]TokenInfo
	Logger *zap.SugaredLogger
}

func (ReplaceToken) CaddyModule

func (ReplaceToken) CaddyModule() caddy.ModuleInfo

CaddyModule returns the Caddy module information.

func (*ReplaceToken) GetTokenInfo

func (c *ReplaceToken) GetTokenInfo(token string) *TokenInfo

func (*ReplaceToken) Provision

func (c *ReplaceToken) Provision(ctx caddy.Context) error

Provision implements caddy.Provisioner.

func (*ReplaceToken) ServeHTTP

func (c *ReplaceToken) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddyhttp.Handler) error

ServeHTTP implements caddyhttp.MiddlewareHandler.

func (ReplaceToken) Validate

func (c ReplaceToken) Validate() error

type TokenInfo

type TokenInfo struct {
	Token     string `json:"token"`
	ExpiresAt int64  `json:"expires_at"`
}

Jump to

Keyboard shortcuts

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