authenticator

package
v0.0.0-...-a59a69c Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2019 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

thanks to @elithrar for the code to create the secret token! source: https://elithrar.github.io/article/generating-secure-random-numbers-crypto-rand/

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateRandomBytes

func GenerateRandomBytes(n int) ([]byte, error)

GenerateRandomBytes returns securely generated random bytes. It will return an error if the system's secure random number generator fails to function correctly, in which case the caller should not continue.

func GenerateRandomString

func GenerateRandomString(s int) (string, error)

GenerateRandomString returns a URL-safe, base64 encoded securely generated random string. It will return an error if the system's secure random number generator fails to function correctly, in which case the caller should not continue.

func Sign

func Sign(key []byte) (string, error)

Sign will generate JWT token with expiry time

func Validate

func Validate(token, key []byte) error

Validate will validate JWT token and return error if invalid

func ValidateToken

func ValidateToken(token []byte) error

Types

type Authenticator

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

func NewAuthenticator

func NewAuthenticator(authStorage storage.UserInteractor, key []byte) *Authenticator

func (*Authenticator) AuthenticateToken

func (auth *Authenticator) AuthenticateToken(authToken, refreshToken, csrfToken string, key []byte) (model.Token, error)

AuthenticateToken check token and return new token

func (*Authenticator) CreateNewToken

func (auth *Authenticator) CreateNewToken(uuid, username string, key []byte) (model.Token, error)

CreateNewToken generate new token with JWT using HS256 method return token and error

func (*Authenticator) RevokeRefreshToken

func (auth *Authenticator) RevokeRefreshToken(refreshToken string) error

RevokeRefreshToken remove refresh token from storage

Jump to

Keyboard shortcuts

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