auth

package
v0.0.0-...-d2dc7f7 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2020 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ComparePasswords

func ComparePasswords(plain, hashed string) bool

ComparePasswords receives the plain and the hashed password, encodes the first one and, tries to compare both of them. It returns true if they are equal. Returns false in any other case.

func Encode

func Encode(body JWT) (*string, *int64, error)

Encode receives a JWT body and retrieves the access token and the time for it to expire. If there is an error, an error is returned instead.

func EncodeUUID

func EncodeUUID(uuid string) string

EncodeUUID receives an UUID and encodes it using base 58.

func GenerateBase58UUID

func GenerateBase58UUID() string

GenerateShortUUID generates an UUID and encodes it using base58.

func GenerateNanoUUID

func GenerateNanoUUID() (string, error)

GenerateNanoUUID generates a user-friendly UUID of length 8.

func GeneratePassword

func GeneratePassword(plain string) (*string, error)

GeneratePassword generates a bcrypt password from the given plain password.

func GenerateUUID

func GenerateUUID() string

GenerateUUID generates an UUID string.

func IsUUID

func IsUUID(value string) bool

IsUUID receives an UUID value and checks if it's a valid UUID.

func Sanitize

func Sanitize(token string) bool

Sanitize makes sure that the given token is valid.

func SplitJWT

func SplitJWT(token string) (header, payload, signature *string)

SplitJWT receives an string and returns the header, the payload and the signature of a JWT.

Types

type Claims

type Claims struct {
	Profile Profile `json:"profile,omitempty"`
	jwt.StandardClaims
}

Claims extends the default claims from the JWT package.

type JWT

type JWT struct {
	UUID  string
	Name  string
	Email string
	Roles roles.Role
}

JWT represents the JWT body that the Authentication algorithm is going to encode.

func Decode

func Decode(token string) (*JWT, error)

Decode tries to convert a string to a JWT. It returns an error if something goes wrong.

type Profile

type Profile struct {
	Email string `json:"email"`
	Name  string `json:"name"`
	Roles roles.Role
}

Profile represents a set of data that is going to be in the JWT body.

Jump to

Keyboard shortcuts

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