auth

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2021 License: Apache-2.0 Imports: 1 Imported by: 5

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

View Source
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

func ClearSecurityContext(ctx context.Context) context.Context

ClearSecurityContext removes the SecurityContext object from the context. Returns a context.Context that does not have a pointer to the SecurityContext object.

func HasAuth

func HasAuth(ctx context.Context) bool

HasAuth checks for existence of Auth object in the given context.Context.

func SetAuth

func SetAuth(ctx context.Context, auth *Auth) context.Context

SetAuth sets the pointer to the Auth object in the context. Returns context.Context that contains the Auth object.

func SetSecurityError

func SetSecurityError(ctx context.Context, secType string, err interface{}) context.Context

SetSecurityError sets an error for the given security type in the SecurityContext. If there is no SecurityContext in the given context, a new one is created implicitly.

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.

func GetAuth

func GetAuth(ctx context.Context) *Auth

GetAuth retrieves the Auth object from the given context.Context. Returns a pointer to the Auth context or nil if no Auth is present in the context.

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.

Jump to

Keyboard shortcuts

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