auth

package
v0.0.0-...-5117fa9 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2018 License: MIT Imports: 7 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrMissingRealm indicates Realm name is required
	ErrMissingRealm = errors.New("realm is missing")

	// ErrForbidden when HTTP status 403 is given
	ErrForbidden = errors.New("you don't have permission to access this resource")

	// ErrInvalidPrivKey indicates that the given private EncryptionKey is invalid
	ErrInvalidClaims = errors.New("token payload content invalid")

	// ErrNoPrivKeyFile indicates that the given private EncryptionKey is unreadable
	ErrNoPrivKeyFile = errors.New("private EncryptionKey file unreadable")

	// ErrNoPubKeyFile indicates that the given public EncryptionKey is unreadable
	ErrNoPubKeyFile = errors.New("public EncryptionKey file unreadable")

	// ErrInvalidPrivKey indicates that the given private EncryptionKey is invalid
	ErrInvalidPrivKey = errors.New("private EncryptionKey invalid")

	// ErrInvalidPubKey indicates the the given public EncryptionKey is invalid
	ErrInvalidPubKey = errors.New("public EncryptionKey invalid")

	// ErrInvalidKey indicates the the given EncryptionKey is invalid
	ErrInvalidKey = errors.New("encrypty EncryptionKey invalid")
)
View Source
var ActiveUserContextKey = contextKey{}

Functions

func ParsePrivateKey

func ParsePrivateKey(priKey []byte) (key *rsa.PrivateKey, err error)

pass through if private key is nil

func ParsePublicKey

func ParsePublicKey(pubKey []byte) (key *rsa.PublicKey, err error)

pass through if public key is nil

Types

type BearerTokenValidator

type BearerTokenValidator struct {
	// Realm name to display to the user. Required.
	Realm string
	// Duration that a jwt token is valid. Optional, defaults to one hour.
	Timeout time.Duration
	// Callback function that should perform the authorization of the authenticated user. Called
	// only after an authentication success. Must return true on success, false on failure.
	// Optional, default to success.
	TokenValidator func(token *jwt.Token, c context.Context) error
	// Set the identity handler function. that mean the jwt is pass validete
	IdentityHandler func(c context.Context, claims jwt.MapClaims) (*Identity, error)
	// Secret EncryptionKey used for signing. Required.
	EncryptionKey []byte
	// Private EncryptionKey
	PrivKey *rsa.PrivateKey
	// Public EncryptionKey
	PubKey *rsa.PublicKey
}

func (*BearerTokenValidator) Init

func (b *BearerTokenValidator) Init() error

Init initialize jwt configs.

func (*BearerTokenValidator) Validate

func (b *BearerTokenValidator) Validate(ctx context.Context, input string) (*Identity, error)

type Identity

type Identity struct {
	// user id
	Id string
	// org id
	OrgId string
}

func UserFromContext

func UserFromContext(ctx context.Context) (*Identity, error)

get User Id from context, grpc interceptor convert metadata into context

func (*Identity) IdInt

func (t *Identity) IdInt() int32

获取int格式的ID,如果id为int的话

func (*Identity) OrgIdInt

func (t *Identity) OrgIdInt() int32

获取int格式的ID,如果id为int的话

Jump to

Keyboard shortcuts

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