claims

package
v0.0.0-...-53bd342 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 6, 2023 License: GPL-3.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RoleAdmin = "ADMIN"
	RoleUser  = "USER"
)

These are the expected values for Claims.Roles.

Variables

This section is empty.

Functions

func IsAdmin

func IsAdmin(ctx context.Context) bool

IsAdmin checks if the session contained in the context, if any, belongs to an administrator. Returns false if no session is found or if the user is not an administrator.

func IsUser

func IsUser(ctx context.Context, id string) bool

IsAdmin checks if the session contained in the context, if any, belongs to the passed user id. Returns false if no session is found or if the user is not equal to the same passed.

func Set

func Set(ctx context.Context, claims Claims) context.Context

Set stores the claims in the context.

Types

type Claims

type Claims struct {
	UserID string
	Role   string
}

Claims represents the authorization claims stored in the session.

func Get

func Get(ctx context.Context) (Claims, error)

Get returns the claims from the context.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL