Documentation ¶
Index ¶
- Constants
- Variables
- func ComparePasswords(hash, password string) (bool, error)
- func GetCookie(r *http.Request, name string) *http.Cookie
- func GetToken(user *User) (string, error)
- func HashPassword(password string) (string, error)
- func RemoveCookie(w http.ResponseWriter, name, path, domain string)
- func SetCookie(w http.ResponseWriter, name, value, path, domain string, maxAge int, ...)
- type CtxKey
- type CtxValues
- type SignedParams
- type User
Constants ¶
const ( RoleSuperAdmin = "superadmin" RoleAdmin = "admin" RoleUser = "user" RoleModerator = "moderator" )
Variables ¶
var ( // ErrorInvalidToken - is a constant that represents an invalid token error. ErrorInvalidToken = errors.New("authorization failed: invalid token") // ErrorExpiredToken - is a constant that represents an expired token error. ErrorExpiredToken = errors.New("authorization failed: expired token") // ErrorInvalidCredentials - is a constant that represents an invalid credentials error. ErrorInvalidCredentials = errors.New("authorization failed: invalid credentials") ErrorUnauthorizedUser = errors.New("authorization failed: unauthorized user") )
var ( Data *SignedParams UserData *User )
Functions ¶
func ComparePasswords ¶
ComparePasswords - ComparePasswords is a function that handles the comparison of passwords.
@param hash - string @param password - string @return bool @return error
func GetCookie ¶
GetCookie - GetCookie is a function that gets a cookie.
@param r - *http.Request @param name - string @return *http.Cookie
func GetToken ¶
GetTokens - is a function that handles the retrieval of tokens.
@param user - *store.User @return string @return string @return error
func HashPassword ¶
HashPassword - HashPassword is a function that handles the hashing of passwords.
@param password - string @return string @return error
func RemoveCookie ¶
func RemoveCookie(w http.ResponseWriter, name, path, domain string)
RemoveCookie - RemoveCookie is a function that deletes a cookie.
@param w - http.ResponseWriter @param name - string @param path - string @param domain - string
func SetCookie ¶
func SetCookie(w http.ResponseWriter, name, value, path, domain string, maxAge int, secure, httpOnly bool, sameSite http.SameSite)
SetCookie - SetCookie is a function that sets a cookie.
@param w - http.ResponseWriter @param name - string @param value - string @param path - string @param domain - string @param maxAge - int @param secure - bool @param httpOnly - bool @param sameSite - http.SameSite
Types ¶
type CtxKey ¶
type CtxKey interface{}
Store Structs
var ContextKey CtxKey = "bookie-api-7kt2" // this is the key that will be used to store the context values
this is the store that will be used to store the context values
type CtxValues ¶
type CtxValues struct {
// contains filtered or unexported fields
}
func (*CtxValues) GetCtxValue ¶
GetValue - returns the value of the context key provided.
@param key - string @return interface{}
func (*CtxValues) SetCtxValue ¶
SetValue - sets the value of the context key provided.
@param key - string @param value - interface{}
type SignedParams ¶
func GetVerifiedClaims ¶
func GetVerifiedClaims(ctx context.Context, role string) (*SignedParams, error)
GetVerifiedClaims - is a function that handles the retrieval of verified claims.
@param ctx - context.Context @param role - string @return *SignedParams @return error
func ValidateToken ¶
func ValidateToken(token string) (*SignedParams, error)
ValidateToken - ValidateToken is a function that handles the verification of tokens.
@param ctx - context.Context @param token - string @param next - func(context.Context) (interface{}, error) @return response @return error
func (*SignedParams) HasRole ¶
func (data *SignedParams) HasRole(roles ...string) bool
HasRole - is a function that checks if a user has a role.
@param ctx - context.Context @param role - string @return bool