server

package
v0.0.0-...-524bf5b Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2023 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package server provides functions for handling different API endpoints of the Go-Auth application.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BadRequest

func BadRequest(err error, relPath string) *api.ProblemDetails

BadRequest is used when user sends a invalid/malformed JSON request. Details are extracted from the error param, if the error param can't be casted as malformedRequest, generic UnexpectedErrorProblem is returned.

func GetProblemDetails

func GetProblemDetails(err error, relPath string) (problem *api.ProblemDetails)

GetProblemDetails is used when a error needs to be identified and user needs a specific problem details response corresponding to the identified error.

func InvalidCredentials

func InvalidCredentials(relPath string) *api.ProblemDetails

InvalidCredentials returns a problem details response used when a user enters invalid login credentials.

func Unauthorized

func Unauthorized(relPaht string) *api.ProblemDetails

func UnexpectedErrorProblem

func UnexpectedErrorProblem(relPath string) *api.ProblemDetails

UnexpectedErrorProblem returns generic problem details response used when an error, about which the user doesn't have to know about, occured.

Types

type GoAuthServer

type GoAuthServer struct{}

GoAuthServer is an empty struct used as a representation of a handler for API endpoints.

func (GoAuthServer) Login

func (s GoAuthServer) Login(w http.ResponseWriter, r *http.Request)

Login handles when a user sends a request to the /login endpoint for logging in. After successfully decoding JSON request, user credentials are compared with corresponding ones retrieved from database. If credentials are valid new JWT token is generated for the user and sent. Specific endpoint details can be found in ./openapi folder in the OpenAPI specification.

func (GoAuthServer) Setup2FA

func (s GoAuthServer) Setup2FA(w http.ResponseWriter, r *http.Request)

Setup2FA creates new 2FA secret for user and returns a 2FA uri for generating QR code.

func (GoAuthServer) Signup

func (s GoAuthServer) Signup(w http.ResponseWriter, r *http.Request)

Signup handles when a user sends a request to the /signup endpoint for signing up. After successfully decoding JSON request, new user entry is saved into the database. Specific endpoint details can be found in ./openapi folder in the OpenAPI specification.

func (GoAuthServer) TestAuth

func (s GoAuthServer) TestAuth(w http.ResponseWriter, r *http.Request)

func (GoAuthServer) Verify2FA

func (s GoAuthServer) Verify2FA(w http.ResponseWriter, r *http.Request)

Jump to

Keyboard shortcuts

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