Documentation ¶
Index ¶
- Constants
- func ContextWithUser(ctx context.Context, u *models.User) context.Context
- func ContextWithUserID(ctx context.Context, uID string) context.Context
- func ExtractRefreshTokenHash(cfg *config.Config, tokenStr string) (string, error)
- func ExtractTokenHash(cfg *config.Config, tokenStr string) (string, error)
- func GetRefreshTokenFromRequest(cfg *config.Config, r *http.Request) (string, error)
- func GetTokenFromRequest(cfg *config.Config, r *http.Request) (string, error)
- func UserFromContext(ctx context.Context) (*models.User, error)
- func UserIDFromContext(ctx context.Context) (string, error)
- type AccessToken
- type JWTAuthService
- type KAuthTokenClaims
- type RefreshToken
- type Tokens
Constants ¶
const ( TokenDuration = time.Hour RefreshTokenDuration = time.Hour * 72 TokenType = "Bearer" )
Various token constants
Variables ¶
This section is empty.
Functions ¶
func ContextWithUser ¶
ContextWithUser returns the copy of the given context with the user key value being the user
func ContextWithUserID ¶
ContextWithUserID returns the copy of the given context with the id key value being the uid
func ExtractRefreshTokenHash ¶
ExtractRefreshTokenHash returns the refresh token hash from the given signed token string Signing method is RSA
func ExtractTokenHash ¶
ExtractTokenHash returns the access token hash from the given signed token string Signing method is HMAC
func GetRefreshTokenFromRequest ¶
GetRefreshTokenFromRequest returns the refresh token string from the request header Signing method is RSA
func GetTokenFromRequest ¶
GetTokenFromRequest returns the access token string from the request header Signing method is HMAC
func UserFromContext ¶
UserFromContext returns the uid from the context user key
Types ¶
type AccessToken ¶
type AccessToken struct {
AccessToken string `json:"accessToken"`
}
AccessToken stores the access token
type JWTAuthService ¶
JWTAuthService is the public interface for auth services
func NewJWTAuthService ¶
func NewJWTAuthService(jwtCfg *config.JWTConfig, redis *database.Redis) JWTAuthService
NewJWTAuthService returns a new JWT auth service
type KAuthTokenClaims ¶
type KAuthTokenClaims struct { jwt.StandardClaims UID string `json:"id"` Admin bool `json:"admin"` TokenHash string `json:"tokenHash"` }
KAuthTokenClaims stores the claims associated with a token
type RefreshToken ¶
type RefreshToken struct {
RefreshToken string `json:"refreshToken"`
}
RefreshToken stores the refresh token