auth

package module
v0.0.0-...-6984e0f Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2022 License: MIT Imports: 9 Imported by: 0

README

gin-auth

Basic Authentication for gin

Example

See the _example folder

Documentation

Index

Constants

View Source
const REALM_STRING string = `Basic realm="Authorization Required"`

Variables

This section is empty.

Functions

This section is empty.

Types

type Auth

type Auth struct {
	LoadUser   LoadUserFunc  // Returns a user from the backing store
	StoreUser  StoreUserFunc // Stores a user to the backing store
	Hash       crypto.Hash   // Hash function to hash the salted password. Use at least SHA-2 (such as SHA-256, SHA-512, etc)
	SaltLength uint          // Length of the generated salts. The generated salt should be at least the same length as the length of the output of the hash function. For example, it should be at least 256/8 = 32 for SHA-256
}

func (*Auth) BasicAuthMiddleware

func (a *Auth) BasicAuthMiddleware(c *gin.Context)

Middleware function for gin

func (*Auth) UpdateUser

func (a *Auth) UpdateUser(username string, password string)

Salts and hashes the password, then calls StoreUser to write the new or updated user to the backing store

type LoadUserFunc

type LoadUserFunc func(username string) (user User, exists bool)

type StoreUserFunc

type StoreUserFunc func(user User)

type User

type User struct {
	Username string
	Password string // hex string of salted hash of the password
	Salt     string
}

Jump to

Keyboard shortcuts

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