Documentation ¶
Index ¶
- Constants
- func AppIDFromContext(ctx context.Context) string
- func AppIDMiddlewareFunc(next http.Handler) http.Handler
- func ExtractTokenFromMetadata(md metadata.MD) (string, error)
- func NewAppIDContext(ctx context.Context, appID string) context.Context
- func NewUserIDContext(ctx context.Context, userID string) context.Context
- func UserIDFromContext(ctx context.Context) string
- func UserIDMiddlewareFunc(next http.Handler) http.Handler
- func WithUser(ctx context.Context, claims *UserClaims) context.Context
- type AuthInterceptor
- type AuthorizerConfig
- type AuthorizerInterceptor
- type CtxProviderClaimsKey
- type JWTManager
- type ProviderClaims
- type UserClaims
Constants ¶
View Source
const ( HeaderUserID = "X-USER-ID" HeaderAppID = "X-APP-ID" )
Variables ¶
This section is empty.
Functions ¶
func AppIDFromContext ¶
func UserIDFromContext ¶
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 ¶
func (i *AuthInterceptor) Unary() grpc.UnaryServerInterceptor
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 ¶
func (i *AuthorizerInterceptor) Unary() grpc.UnaryServerInterceptor
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.
Click to show internal directories.
Click to hide internal directories.