auth

package
v0.0.0-...-61905c3 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2023 License: GPL-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AccessTokenExpiration  = time.Minute * 15
	RefreshTokenExpiration = time.Hour * 48
)
View Source
const AccessTokenIssuer = "semaphore"

Variables

View Source
var DefaultJwtKeyFunc = func(key []byte) jwt.Keyfunc {
	return func(token *jwt.Token) (interface{}, error) {
		return key, nil
	}
}

Functions

func GenerateAccessToken

func GenerateAccessToken(usr user.User, key []byte, expiresIn time.Duration) (string, error)

func GenerateRefreshToken

func GenerateRefreshToken(usr user.User, key []byte, expiresIn time.Duration) (string, error)

func GenerateTokenPair

func GenerateTokenPair(usr user.User, key []byte) (accessToken string, refreshToken string, err error)

Types

type AccessToken

type AccessToken struct {
	jwt.RegisteredClaims
	User UserInfo `json:"user"`
}

AccessToken represents jwt claims for user.

func ValidateAccessToken

func ValidateAccessToken(token string, keyFunc jwt.Keyfunc) (*AccessToken, error)

type RefreshToken

type RefreshToken struct {
	jwt.RegisteredClaims
}

RefreshToken represents jwt claims for user refresh token.

func ValidateRefreshToken

func ValidateRefreshToken(token string, keyFunc jwt.Keyfunc) (*RefreshToken, error)

type UserInfo

type UserInfo struct {
	ID        uint   `json:"id"`
	Email     string `json:"email"`
	FirstName string `json:"firstname"`
	LastName  string `json:"lastname"`
}

UserInfo represents user info that will be part of AccessToken.

Jump to

Keyboard shortcuts

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