Documentation ¶
Index ¶
- Constants
- Variables
- func CheckHasRole(ctx context.Context, logger *logpkg.Logger, w http.ResponseWriter, ...) bool
- func GetAccountIDFromCtx(ctx context.Context) (int64, errorsx.Error)
- func GetIDFromCtx(ctx context.Context) (int64, errorsx.Error)
- func GetRoleIDsFromCtx(ctx context.Context) ([]int64, errorsx.Error)
- func HasRoleID(ctx context.Context, roleID int64) (bool, errorsx.Error)
- type Token
Constants ¶
View Source
const ( JwtIDKey = "id" JwtAccountIDKey = "account" JwtRoleIDsKey = "roles" )
Variables ¶
View Source
var ( TokenIDCtxKey = ctxKey{Name: "TokenID"} TokenAccountIDCtxKey = ctxKey{Name: "AccountID"} TokenRoleIDsCtxKey = ctxKey{Name: "RoleIDs"} )
Functions ¶
func CheckHasRole ¶
func CheckHasRole(ctx context.Context, logger *logpkg.Logger, w http.ResponseWriter, r *http.Request, roleID int64) bool
CheckHasRole checks if a user has a given role. It returns a boolean: if the execution should continue or not. If the user doesn't have the role it, logs to the logger and returns 403. If there is any other error, it returns 500
Types ¶
type Token ¶
type Token struct { // ID of the token (if required) ID int64 // ID of the "account" the token belongs to (probably creaated by) // This could be e.g. a user ID, or an organisation ID AccountID int64 Name string // RoleIDs the token has. This can be used the user has access to the endpoint they are trying to access RoleIDs []int64 CreatedAt time.Time }
Click to show internal directories.
Click to hide internal directories.