Documentation
¶
Overview ¶
Package auth exports structure (type) for storing Authorization data and tools for accessing and setting the Auth object in provided context.Context.
Index ¶
- Constants
- func ClearSecurityContext(ctx context.Context) context.Context
- func HasAuth(ctx context.Context) bool
- func SetAuth(ctx context.Context, auth *Auth) context.Context
- func SetSecurityError(ctx context.Context, secType string, err interface{}) context.Context
- type Auth
- type SecurityContext
- type SecurityErrors
Constants ¶
const (
// SecurityContextKey is the context key under which the SecurityContext object is stored in context.Context.
SecurityContextKey key = "security-context"
)
Variables ¶
This section is empty.
Functions ¶
func ClearSecurityContext ¶
ClearSecurityContext removes the SecurityContext object from the context. Returns a context.Context that does not have a pointer to the SecurityContext object.
Types ¶
type Auth ¶
type Auth struct {
// UserID is the ID of the authenticated user.
UserID string `json:"userId,omitempty"`
// CustomerID is the ID of the customer to which the authenticated user belongs.
CustomerID float64 `json:"customerID,omitempty"`
// Username is the username of the authenticated user.
Username string `json:"username,omitempty"`
// Fullname is the first name and surname of the authenticated user.
Fullname string `json:"fullname,omitempty"`
// Email is the email of the authenticated user.
Email string `json:"email,omitempty"`
// Roles is the list of roles that the user has claimed and have been authorized by the system.
Roles []string `json:"roles,omitempty"`
// Organizations is the list of organizations that the user belongs to. This is a list of
// authorized ogranization based on the security claim.
Organizations []string `json:"organizations,omitempty"`
// Namespaces is the list of namespaces that this user belongs to.
Namespaces []string `json:"namespaces"`
}
Auth stores the Authorization and Authentication data for a particular user/client.
type SecurityContext ¶
type SecurityContext struct {
*Auth
Errors SecurityErrors
}
SecurityContext holds pointer to the Auth object and a SecurityErrors. It is created for each request and is kept in the context.Context for that request.
func GetSecurityContext ¶
func GetSecurityContext(ctx context.Context) *SecurityContext
GetSecurityContext returns the SecurityContext from the given context. If not found, it returns nil.
type SecurityErrors ¶
type SecurityErrors map[string]interface{}
SecurityErrors holds the errors generated during validation of the request with a specific security mechanism (ex. JWT, SAML, OAuth2).
func GetSecurityErrors ¶
func GetSecurityErrors(ctx context.Context) *SecurityErrors
GetSecurityErrors returns the SecurityErrors map from the SecurityContext in the given context. If no SecurityContext exists in the current context, it returns nil.