server

package
v0.0.0-...-0e99106 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2022 License: GPL-3.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var LogFile string = "./dat/log/authserver.log"

Functions

func CloseLog

func CloseLog()

CloseLog closes the current log file and rewrites it to a separate file

func Log

func Log(format string, args ...interface{}) error

Log writes a format string to the current open log file

func OpenLog

func OpenLog() error

OpenLog opens a log file to target with Log

func ReadRequestBody

func ReadRequestBody(out *AuthRequestBody, req *http.Request) error

Read the body of an http request with AuthRequestBody params.

Input:

  • out *AuthRequestBody: Pointer to an AuthRequestBody object to read data into
  • req *http.Request: Request to read from. This uses ioutil.ReadAll, which means it depletes the buffer; trying to call any other read on the request after ReadRequestBody will make the body appear to be empty.

Output:

  • Error, if one occurs. Non-POST requests and invalid JSON will cause this.

func WriteResponse

func WriteResponse(w http.ResponseWriter, code int, msg string)

Write out an HTTP response with a code/message.

Input:

  • w http.ResponseWriter: These are always given to http-response-capable functions; just pass that here.
  • code int: HTTP response code.
  • msg string: Message to send with the code. Technically optional, though very good form to include an informative body, especially with codes >399.

Types

type AuthRequestBody

type AuthRequestBody struct {
	Email       string `json:"email"`
	Username    string `json:"username"`
	Password    string `json:"password"`
	NewPassword string `json:"newPassword"`
	Code        string `json:"authCode"`
	GetKey      bool   `json:"getKey"`
	Key         string `json:"gateKey"`
}

Request body format for all authentication requests.

type AuthServer

type AuthServer struct {
	Config *AuthServerConfig // Configuration settings
	Open   bool              // Is server open to API calls?
	// contains filtered or unexported fields
}

An AServer holds the information needed to fulfill authentication.

func NewServer

func NewServer(cfg *AuthServerConfig) *AuthServer

Create a new AuthServer (authentication server) using an AuthServerConfig.

Input:

  • cfg *AuthServerConfig: Target configuration. Should be non-nil.

Output:

  • *AuthServer: A new server object containing configuration, an *http.Server, and a waitgroup

func (*AuthServer) HandleCodeAuthRequest

func (s *AuthServer) HandleCodeAuthRequest(w http.ResponseWriter, req *http.Request)

Handle authentication code requests

func (*AuthServer) HandleEmailAuthRequest

func (s *AuthServer) HandleEmailAuthRequest(w http.ResponseWriter, req *http.Request)

Handle email authentication requests

func (*AuthServer) HandleKeyAuthRequest

func (s *AuthServer) HandleKeyAuthRequest(w http.ResponseWriter, req *http.Request)

func (*AuthServer) SMTPHost

func (srv *AuthServer) SMTPHost() gatemail.Host

Create a mail host from the calling server's configuration.

Calling:

  • srv *AuthServer: Server to use with this SMTP configuration

Output:

  • (gate)mail.Host: SMTP host for use with pkg/mail.

func (*AuthServer) Start

func (s *AuthServer) Start()

Start an authentication server. This has two different behaviors; a new server with an empty database and any other server. New users will have to create an admin account, be provided with a randomly-generated password and an API key, and then asked to restart the server.

Calling:

  • s *AuthServer: Server to run. Should be initialized with NewServer before calling Start.

func (*AuthServer) Stop

func (s *AuthServer) Stop()

Stop the server. Waits to return until everything closes out.

type AuthServerConfig

type AuthServerConfig struct {
	Domain   string         `yaml:"Domain"`
	Port     int            `yaml:"Port"`
	SMTPHost SMTPHostConfig `yaml:"SMTPHost"`
	DB       DBConfig       `yaml:"Database"`
	JWT      JWTConfig      `yaml:"JWT"`
}

ServerConfig defines configuration settings for the authentication server. ENV values are environment variable names

func NewConfig

func NewConfig() *AuthServerConfig

func (*AuthServerConfig) ReadConfig

func (cfg *AuthServerConfig) ReadConfig(fn string) error

Read a configuration file into the calling *AuthServerConfig.

Calling:

  • cfg *AuthServerConfig: Config to read file into. If no error results, cfg should be fully populated.

Output:

  • error: Any error that occurs when reading, including: file doesn't exist, invalid yaml format, envs not present

type DBConfig

type DBConfig struct {
	Path string `yaml:"Path"`
}

type Dashboard

type Dashboard struct {
	Data DashboardData
	// contains filtered or unexported fields
}

The Dashboard is a site that allows control over the authentication server. It also serves as a handler for incoming requests; see ServeHTTP below

func (*Dashboard) ServeHTTP

func (d *Dashboard) ServeHTTP(w http.ResponseWriter, r *http.Request)

Serve requests to dashboard. This implements the http.Handler interface on Dashboard.

type DashboardData

type DashboardData struct {
	AppName string
	EmailOk bool
	TLSOk   bool
}

Persistent data for Dashboard.

type JWTConfig

type JWTConfig struct {
	TokenSecret_ENV string `yaml:"ENV_TokenSecret"`
	TokenSecret     string `yaml:"-"`
	UserValidTime   int    `yaml:"UserValidTime"`
	AdminValidTime  int    `yaml:"AdminValidTime"`
}

type SMTPHostConfig

type SMTPHostConfig struct {
	Username_ENV string `yaml:"ENV_Username"`
	Username     string `yaml:"-"`
	Password_ENV string `yaml:"ENV_Password"`
	Password     string `yaml:"-"`
	Host         string `yaml:"Host"`
	Port         int    `yaml:"Port"`
	Sender       string `yaml:"Sender"`
	TestEmail    string `yaml:"TestEmail"`
}

Jump to

Keyboard shortcuts

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