Documentation ¶
Index ¶
- Variables
- func CloseLog()
- func Log(format string, args ...interface{}) error
- func OpenLog() error
- func ReadRequestBody(out *AuthRequestBody, req *http.Request) error
- func WriteResponse(w http.ResponseWriter, code int, msg string)
- type AuthRequestBody
- type AuthServer
- func (s *AuthServer) HandleCodeAuthRequest(w http.ResponseWriter, req *http.Request)
- func (s *AuthServer) HandleEmailAuthRequest(w http.ResponseWriter, req *http.Request)
- func (s *AuthServer) HandleKeyAuthRequest(w http.ResponseWriter, req *http.Request)
- func (srv *AuthServer) SMTPHost() gatemail.Host
- func (s *AuthServer) Start()
- func (s *AuthServer) Stop()
- type AuthServerConfig
- type DBConfig
- type Dashboard
- type DashboardData
- type JWTConfig
- type SMTPHostConfig
Constants ¶
This section is empty.
Variables ¶
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 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 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
type DashboardData ¶
Persistent data for Dashboard.