auth

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2024 License: MIT Imports: 12 Imported by: 1

Documentation

Index

Constants

View Source
const (
	HeaderUserID = "X-USER-ID"
	HeaderAppID  = "X-APP-ID"
)

Variables

This section is empty.

Functions

func AppIDFromContext

func AppIDFromContext(ctx context.Context) string

func AppIDMiddlewareFunc

func AppIDMiddlewareFunc(next http.Handler) http.Handler

func ExtractTokenFromMetadata

func ExtractTokenFromMetadata(md metadata.MD) (string, error)

func NewAppIDContext

func NewAppIDContext(ctx context.Context, appID string) context.Context

func NewUserIDContext

func NewUserIDContext(ctx context.Context, userID string) context.Context

func UserIDFromContext

func UserIDFromContext(ctx context.Context) string

func UserIDMiddlewareFunc

func UserIDMiddlewareFunc(next http.Handler) http.Handler

func WithUser

func WithUser(ctx context.Context, claims *UserClaims) context.Context

WithUser sets user claims on the context.

Types

type AuthInterceptor

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

func NewAuthInterceptor

func NewAuthInterceptor(logger *zap.Logger, jwtManager *JWTManager, authRoles map[string][]string) *AuthInterceptor

func (*AuthInterceptor) Unary

Unary returns a server interceptor function to authenticate and authorize unary RPC.

type AuthorizerConfig

type AuthorizerConfig struct {
	Secret string
}

type AuthorizerInterceptor

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

func NewAuthorizerInterceptor

func NewAuthorizerInterceptor(logger *zap.Logger, jwtManager *JWTManager, config *AuthorizerConfig) *AuthorizerInterceptor

func (*AuthorizerInterceptor) Unary

Unary returns a server interceptor function to authenticate and authorize unary RPC.

type CtxProviderClaimsKey

type CtxProviderClaimsKey struct{}

type JWTManager

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

JWTManager is a JSON web token manager.

func NewJWTManager

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

NewJWTManager returns a new JWT manager.

func (*JWTManager) Verify

func (m *JWTManager) Verify(accessToken string) (*UserClaims, error)

Verify verifies the access token string and return a user claim if the token is valid.

type ProviderClaims

type ProviderClaims struct {
	jwt.StandardClaims
}

type UserClaims

type UserClaims struct {
	jwt.StandardClaims
	Role     string `json:"role,omitempty"`
	Nid      string `json:"nid,omitempty"`
	Username string `json:"username,omitempty"`
}

UserClaims is a custom JWT claims that contains some user's information.

func GetUserFromContext

func GetUserFromContext(ctx context.Context) (*UserClaims, bool)

GetUserFromContext reads the user claims from the context.

Jump to

Keyboard shortcuts

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