auth

package
v0.0.0-...-59cac3b Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2021 License: GPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AuthenticateWithDatabase

func AuthenticateWithDatabase(authD ValidationPair, userDB rdb.Database) (username string, token string, err error)

Verify that claimed authentication details are stored in database, if so return stored username, token, and ok=true

func CreateOrUpdateAuthSecretInFile

func CreateOrUpdateAuthSecretInFile()

Creates or updates the GG_ACCESS_SECRET value in secrets.env

func ExtractToken

func ExtractToken(r *http.Request) (token string, ok bool)

Extract Token from request header

func GenerateRandomSecureString

func GenerateRandomSecureString(n int) (string, error)

Generate random string of n characters

func GenerateToken

func GenerateToken(username string) (string, error)

Generates a new token based on username and gg_access_secret

func GenerateTokenValidationMiddlewareFunc

func GenerateTokenValidationMiddlewareFunc(userDB rdb.Database) func(http.Handler) http.Handler

Generates a middleware function for handling token validation on secure routes

func LoadSecretsToEnv

func LoadSecretsToEnv()

Load secrets.env file to environment

func ValidateUserToken

func ValidateUserToken(r *http.Request, userDB rdb.Database) (username string, token string, err error)

Extract token metadata and check claimed token against database

func ValidateUsername

func ValidateUsername(username string) string

validate that username meets spec

func VerifyTokenFormatAndDecode

func VerifyTokenFormatAndDecode(r *http.Request) (jwt.Token, error)

Extract token from header then parse and ensure confirms to signing method, if so return decoded token

Types

type ValidationPair

type ValidationPair struct {
	Username string
	Token    string
}

Defines struct for passing around Token-Username pairs

func ExtractTokenMetadata

func ExtractTokenMetadata(r *http.Request) (ValidationPair, error)

Verify token format and decode, then extract metadata (e.g. username) and return

type ValidationResponseKey

type ValidationResponseKey int

enum for ValidationContext

const (
	ValidationContext ValidationResponseKey = iota
)

Jump to

Keyboard shortcuts

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