jwt

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2021 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidRoleclaims = errors.New("invalid role claims")
	Admin                = []string{admin}
	User                 = []string{user}
	Both                 = []string{admin, user}
)

Functions

func Decode

func Decode(pemEncoded string) *ecdsa.PrivateKey

func Encode

func Encode(privateKey *ecdsa.PrivateKey) string

func FromBase58

func FromBase58(key string) (*ecdsa.PrivateKey, error)

func New

func New() (*ecdsa.PrivateKey, *ecdsa.PublicKey)

func NewBase58Key

func NewBase58Key() string

Types

type AuthInterceptor

type AuthInterceptor struct {
	Authorizer AuthorizeFn
	// contains filtered or unexported fields
}

func NewAuthInterceptor

func NewAuthInterceptor(Authorizer AuthorizeFn) *AuthInterceptor

func (*AuthInterceptor) Stream

func (*AuthInterceptor) Unary

type AuthorizeFn

type AuthorizeFn func(ctx context.Context, method string) error

func DefaultAuthorizer

func DefaultAuthorizer(jwtManager *JWTManager, accessibleRoles map[string][]string) AuthorizeFn

type JWTManager

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

func NewJWTManager

func NewJWTManager(secretKey string, tokenDuration time.Duration) (*JWTManager, error)

func (*JWTManager) Generate

func (m *JWTManager) Generate(roles []string) (string, error)

func (*JWTManager) Refresh

func (m *JWTManager) Refresh(token string) (string, error)

func (*JWTManager) Verify

func (m *JWTManager) Verify(token string) (*RoleClaims, error)

type RoleClaims

type RoleClaims struct {
	jwt.StandardClaims
	Roles []string `json:"roles"`
}

func (*RoleClaims) IsAuthorized

func (r *RoleClaims) IsAuthorized(role string) bool

func (*RoleClaims) String

func (r *RoleClaims) String() string

Jump to

Keyboard shortcuts

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