service

package
v2.9.0 Latest Latest
Warning

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

Go to latest
Published: May 9, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// PayloadName is a JWT token payload "name".
	PayloadName = "name"
)

Variables

View Source
var (
	// ErrCreatingToken is a token creation error.
	ErrCreatingToken = errors.New("Error creating token")
	// ErrSavingToken is a token saving error.
	ErrSavingToken = errors.New("Error saving token")
	// ErrInvalidApp is when the application is not eligible to obtain the token
	ErrInvalidApp = errors.New("Application is not eligible to obtain the token")
	// ErrInvalidOfflineScope is when the requested scope does not have an offline value.
	ErrInvalidOfflineScope = errors.New("Requested scope don't have offline value")
	// ErrInvalidUser is when the user cannot obtain the new token.
	ErrInvalidUser = errors.New("The user cannot obtain the new token")

	// TokenLifespan is a token expiration time, one week.
	TokenLifespan = int64(604800) // int64(1*7*24*60*60)
	// InviteTokenLifespan is an invite token expiration time, one hour.
	InviteTokenLifespan = int64(3600) // int64(1*60*60)
	// RefreshTokenLifespan is a default expiration time for refresh tokens, one year.
	RefreshTokenLifespan = int64(31536000) // int(365*24*60*60)
)

Functions

func NewJWTokenService

func NewJWTokenService(privateKey interface{}, issuer string, tokenStorage model.TokenStorage, appStorage model.AppStorage, userStorage model.UserStorage, options ...func(model.TokenService) error) (model.TokenService, error)

NewJWTokenService returns new JWT token service. Arguments: - privateKeyPath - the path to the private key in pem format. Please keep it in a secret place. - publicKeyPath - the path to the public key.

func ResetTokenLifespan

func ResetTokenLifespan(lifespan int64) func(*JWTokenService) error

ResetTokenLifespan sets custom lifespan in seconds for the reset token

func WebCookieTokenLifespan

func WebCookieTokenLifespan(lifespan int64) func(*JWTokenService) error

WebCookieTokenLifespan sets custom lifespan in seconds for the web cookie token

Types

type JWTokenService

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

JWTokenService is a JWT token service.

func (*JWTokenService) Algorithm

func (ts *JWTokenService) Algorithm() string

Algorithm returns signature algorithm.

func (*JWTokenService) Issuer

func (ts *JWTokenService) Issuer() string

Issuer returns token issuer name.

func (*JWTokenService) KeyID

func (ts *JWTokenService) KeyID() string

KeyID returns public key ID, using SHA-1 fingerprint.

func (*JWTokenService) NewAccessToken

func (ts *JWTokenService) NewAccessToken(u model.User, scopes []string, app model.AppData, requireTFA bool, tokenPayload map[string]interface{}) (model.Token, error)

NewAccessToken creates new access token for user.

func (*JWTokenService) NewInviteToken

func (ts *JWTokenService) NewInviteToken(email, role, audience string, data map[string]interface{}) (model.Token, error)

NewInviteToken creates new invite token.

func (*JWTokenService) NewRefreshToken

func (ts *JWTokenService) NewRefreshToken(u model.User, scopes []string, app model.AppData) (model.Token, error)

NewRefreshToken creates new refresh token.

func (*JWTokenService) NewResetToken

func (ts *JWTokenService) NewResetToken(userID string) (model.Token, error)

NewResetToken creates new token for password resetting.

func (*JWTokenService) NewWebCookieToken

func (ts *JWTokenService) NewWebCookieToken(u model.User) (model.Token, error)

NewWebCookieToken creates new web cookie token.

func (*JWTokenService) Parse

func (ts *JWTokenService) Parse(s string) (model.Token, error)

Parse parses token data from the string representation.

func (*JWTokenService) PrivateKey

func (ts *JWTokenService) PrivateKey() interface{}

func (*JWTokenService) PublicKey

func (ts *JWTokenService) PublicKey() interface{}

PublicKey returns public key.

func (*JWTokenService) RefreshAccessToken

func (ts *JWTokenService) RefreshAccessToken(refreshToken model.Token, tokenPayload map[string]interface{}) (model.Token, error)

RefreshAccessToken issues new access token for provided refresh token.

func (*JWTokenService) SetPrivateKey

func (ts *JWTokenService) SetPrivateKey(key interface{})

func (*JWTokenService) String

func (ts *JWTokenService) String(t model.Token) (string, error)

String returns string representation of a token.

func (*JWTokenService) ValidateTokenString

func (ts *JWTokenService) ValidateTokenString(tstr string, v jwtValidator.Validator, tokenType string) (model.Token, error)

ValidateTokenString parses token and validates it.

func (*JWTokenService) WebCookieTokenLifespan

func (ts *JWTokenService) WebCookieTokenLifespan() int64

WebCookieTokenLifespan return auth token lifespan

Jump to

Keyboard shortcuts

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