Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // ErrFailedToCreateAccessToken indicates access Token failed to create, reason unknown ErrFailedToCreateAccessToken = errors.New("failed to create access Token") // ErrFailedToCreateRefreshToken indicates refresh Token failed to create, reason unknown ErrFailedToCreateRefreshToken = errors.New("failed to create refresh Token") // ErrEmptyAccessSecretKey indicates access secret key is empty ErrEmptyAccessSecretKey = errors.New("empty access token secret key") // ErrEmptyGetUserFunc indicates get user func is empty ErrEmptyGetUserFunc = errors.New("empty get user by id func") // ErrEmptyAuthenticator indicates authentication function is empty ErrEmptyAuthenticator = errors.New("empty authentication function") // ErrEmptyStorage indicates storage is not provided ErrEmptyStorage = errors.New("empty storage") // ErrCannotSaveToken indicates token is failed to save, reason unknown ErrCannotSaveToken = errors.New("failed to save token from storage") // ErrCannotDeleteToken indicates token is failed to delete, reason unknown ErrCannotDeleteToken = errors.New("failed to delete token from storage") // ErrUnknownSigningMethod indicates unknown signing method provided ErrUnknownSigningMethod = errors.New("unknown signing method provided") // ErrInvalidSigningMethod indicates signing method id invalid ErrInvalidSigningMethod = errors.New("invalid signing method") // ErrTokenExpired indicates token has expired ErrTokenExpired = errors.New("token has expired") // ErrTokenInvalid indicates token is not valid ErrTokenInvalid = errors.New("token is not valid") // ErrRefreshTokenIsNotProvided indicates refresh token is not provided ErrRefreshTokenIsNotProvided = errors.New("refresh token is not provided") // ErrNoAuthHeader indicates no auth header is provided ErrNoAuthHeader = errors.New("no auth header provided") // ErrInvalidAuthHeader indicates auth header is not valid ErrInvalidAuthHeader = errors.New("invalid auth header") // ErrUserIdIsNotProvided indicates user id is not provided ErrUserIdIsNotProvided = errors.New("user id is not provided") // ErrNotAuthUser indicates user is not authenticated ErrNotAuthUser = errors.New("user is not authenticated") )
View Source
var (
UserKey = "user"
)
Functions ¶
This section is empty.
Types ¶
type DefaultErrResponse ¶ added in v1.0.3
type DefaultLoginResponse ¶ added in v1.0.3
type DefaultLogoutResponse ¶ added in v1.0.3
type DefaultLogoutResponse struct{}
type Gwt ¶
type Gwt struct { Service *Service Handler *Handler Middleware *Middleware }
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
func (*Handler) GetForceLogoutHandler ¶
func (*Handler) GetLoginHandler ¶
func (*Handler) GetLogoutHandler ¶
func (*Handler) GetRefreshHandler ¶
type Middleware ¶
type Middleware struct {
// contains filtered or unexported fields
}
func (*Middleware) GetAuthMiddleware ¶
func (mw *Middleware) GetAuthMiddleware() gin.HandlerFunc
type RefreshRequestData ¶ added in v1.0.4
type RefreshRequestData struct {
RefreshToken string `json:"refresh_token"`
}
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
func (*Service) ForceLogoutUser ¶
type Settings ¶
type Settings struct { // SigningMethod signing algorithm - possible values are HS256, HS384, HS512 // Optional, default is HS256. SigningMethod string // AccessSecretKey used for signing. Required. AccessSecretKey []byte // RefreshSecretKey used for signing. Optional, AccessSecretKey is used by default. RefreshSecretKey []byte // AccessLifetime is a duration that an access token is valid. Optional, ten minutes by defaults. AccessLifetime time.Duration // RefreshLifetime is a duration that a refresh token is valid. Optional, one day by defaults. RefreshLifetime time.Duration // AdditionalAuthHeader is the header that will be used with default Authorization header // data from this header will be copied into default // this feature can be used to avoid Safari bug // when safari gets 3xx response, Authentication header will be broken in next request AdditionalAuthHeader string // AuthHeadName is a string in the header. Default value is "Bearer" AuthHeadName string // Callback function that should perform the authentication of the user based on login info. // Must return user id as string. Required. Authenticator func(c *gin.Context) (string, error) // GetUserFunc is function than returns application user model GetUserFunc func(userId string) (interface{}, error) // LoginResponseFunc is function that returns data after successful authentication LoginResponseFunc func(c *gin.Context, code int, accessToken string, accessExpire int64, refreshToken string, refreshExpire int64) // LoginResponseFunc is function that returns data after successful logout LogoutResponseFunc func(c *gin.Context, code int) // LoginResponseFunc is function that returns data after an error has been happened ErrResponseFunc func(c *gin.Context, code int, message string) // Storage is struct than stores auth data Storage StorageInterface }
type StorageInterface ¶
type StorageInterface interface { DeleteTokens(userId string, uuid ...string) error SaveTokens(userId string, accessUuid string, refreshUuid string, accessExpire int64, refreshExpire int64, accessToken string, refreshToken string) error HasRefreshToken(uuid string, token string, userId string) error HasAccessToken(uuid string, token string, userId string) error DeleteAllTokens(userId string) error }
Source Files ¶
Click to show internal directories.
Click to hide internal directories.