Documentation ¶
Index ¶
- Constants
- type AccessTokenCustomClaims
- type Extractor
- type JWTManager
- func (j *JWTManager) GenerateAccessToken(user *data.User) (string, error)
- func (j *JWTManager) GenerateCustomKey(userID string, tokenHash string) string
- func (j *JWTManager) GenerateRefreshToken(user *data.User) (string, error)
- func (j *JWTManager) ValidateAccessToken(tokenString string) (*AccessTokenCustomClaims, error)
- func (j *JWTManager) ValidateRefreshToken(tokenString string) (*RefreshTokenCustomClaims, error)
- type RefreshTokenCustomClaims
- type TokenManager
- type User
Constants ¶
const (
// HeaderName ...
HeaderName = "Authorization"
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AccessTokenCustomClaims ¶
type AccessTokenCustomClaims struct { UserID string `json:"user_id,omitempty"` KeyType string `json:"key_type,omitempty"` Roles []string `json:"roles,omitempty"` jwt.StandardClaims }
AccessTokenCustomClaims specifies the claims for access token
type Extractor ¶
type Extractor interface { ExtractGRPC(ctx context.Context) (header string, err error) ExtractHTTP(r *http.Request) (header string, err error) }
Extractor ...
type JWTManager ¶
type JWTManager struct {
// contains filtered or unexported fields
}
func NewJWTManager ¶
func NewJWTManager(logger hclog.Logger, configs *utils.Configurations) *JWTManager
func (*JWTManager) GenerateAccessToken ¶
func (j *JWTManager) GenerateAccessToken(user *data.User) (string, error)
GenerateAccessToken generates a new access token for the given user
func (*JWTManager) GenerateCustomKey ¶
func (j *JWTManager) GenerateCustomKey(userID string, tokenHash string) string
GenerateCustomKey creates a new key for our jwt payload the key is a hashed combination of the userID and user tokenhash
func (*JWTManager) GenerateRefreshToken ¶
func (j *JWTManager) GenerateRefreshToken(user *data.User) (string, error)
GenerateRefreshToken generate a new refresh token for the given user
func (*JWTManager) ValidateAccessToken ¶
func (j *JWTManager) ValidateAccessToken(tokenString string) (*AccessTokenCustomClaims, error)
ValidateAccessToken parses and validates the given access token returns the userId present in the token payload
func (*JWTManager) ValidateRefreshToken ¶
func (j *JWTManager) ValidateRefreshToken(tokenString string) (*RefreshTokenCustomClaims, error)
ValidateRefreshToken parses and validates the given refresh token returns the userId and customkey present in the token payload
type RefreshTokenCustomClaims ¶
type RefreshTokenCustomClaims struct { UserID string `json:"user_id,omitempty"` CustomKey string `json:"custom_key,omitempty"` KeyType string `json:"key_type,omitempty"` jwt.StandardClaims }
RefreshTokenCustomClaims specifies the claims for refresh token
type TokenManager ¶
type TokenManager interface { GenerateAccessToken(user *data.User) (string, error) GenerateRefreshToken(user *data.User) (string, error) GenerateCustomKey(userID string, password string) string ValidateAccessToken(token string) (string, error) ValidateRefreshToken(token string) (string, string, error) }
Authentication interface lists the methods that our authentication service should implement