auth

package
v0.0.0-...-cbce884 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2020 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// AccessTokenExpiry is how long access tokens last.
	AccessTokenExpiry = 15 // 15 minutes
	// RefreshTokenExpiry is the period of time that refresh tokens are valid.
	RefreshTokenExpiry = 60 * 24 * 3 // 3 days
)
View Source
const (
	// RoleUser is a constant value for the user role
	RoleUser = "user"
	// RoleAdmin is a constant value for the admin role
	RoleAdmin = "admin"
	// RoleAnon is a constant value for an anonymous role
	RoleAnon = "anonymous"
)

Variables

View Source
var ValidRoles = [2]string{RoleUser, RoleAdmin}

ValidRoles is a list of allowed roles for project users and api keys

Functions

func CompareHashAndPassword

func CompareHashAndPassword(hash, password string) bool

CompareHashAndPassword compares the hash value to the password.

func HashPassword

func HashPassword(password string) (string, error)

HashPassword returns the bcrypt hash of the password.

func RecaptchaSiteVerify

func RecaptchaSiteVerify(clientResponse, reCaptchaSecret string) error

RecaptchaSiteVerify verifies the client response with recaptcha

func SHA1

func SHA1(text, appSecret string) string

SHA1 hashes using sha1 algorithm Used for api keys

Types

type JWT

type JWT struct {
	// contains filtered or unexported fields
}

JWT wraps functions need to create and parse JWTs

func NewJWT

func NewJWT(config *config.AppConfig) *JWT

NewJWT creates and returns a pointer to a new `JWT`

func (*JWT) CreateAccessToken

func (j *JWT) CreateAccessToken(claims jwt.MapClaims) (string, error)

CreateAccessToken creates a new JWT to be used as an access token.

func (*JWT) CreateJWT

func (j *JWT) CreateJWT(claims jwt.MapClaims, expiry int64) (string, error)

CreateJWT creates a new JWT. This function will add the `exp` key to the claims based on the expiry time.

func (*JWT) CreateRefreshToken

func (j *JWT) CreateRefreshToken(sessionID, userID string) (string, error)

CreateRefreshToken creates a new JWT to be used as the refresh token. The refresh token can be used to retrieve a new access token.

func (*JWT) TokenLookup

func (j *JWT) TokenLookup(token *jwt.Token) (interface{}, error)

TokenLookup returns an error if the JWT is invalid.

Jump to

Keyboard shortcuts

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