demo

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2021 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ClaimAppAuthenticated = "authn"
	ClaimAppRoles         = "roles"

	ClaimAudience  = "aud"
	ClaimExpires   = "exp"
	ClaimIssuer    = "iss"
	ClaimIssuedAt  = "iat"
	ClaimNotBefore = "nbf"
	ClaimSubject   = "sub"

	ClaimRoleUser    = "user"
	ClaimRoleAPIUser = "api-user"

	ContextKeyAPIStateCode = "api_state_code"
	ContextKeyAPIError     = "api_error"
)

JWT claim constants

View Source
const (
	ErrorMimeType = "error"
)

Variables

This section is empty.

Functions

func ErrorHandler

func ErrorHandler(c *gin.Context, errorCode string, err error) bool

ErrorHandler handles any errors that arise as part of the JWT authentication and validation process.

func IsAuthenticated

func IsAuthenticated(ctx *gin.Context, token *jwt.Token) (bool, error)

IsAuthenticated determines whether or not the JWT token indicates the user has been authenticated.

If the token is valid and not expired, no error is returned. The boolean status will indicate whether or not the user has been authenticated.

The following errors are returned by this function: APITokenExpired, APITokenInvalid, APITokenNotAuthenticated

func IsAuthorized

func IsAuthorized(ctx *gin.Context, token *jwt.Token) (bool, error)

IsAuthorized determines whether or not the JWT token indicates the user is authorized to perform an action.

The following errors are returned by this function: APITokenInvalid

Types

type ErrorResponse

type ErrorResponse struct {
	// contains filtered or unexported fields
}

ErrorResponse holds details used to send an error response for a request.

func NewErrorResponse

func NewErrorResponse(ctx *gin.Context, statusCode int, message string, err error,
	details ...map[string]interface{}) *ErrorResponse

NewErrorResponse constructs and initializes a new ErrorResponse object.

func (*ErrorResponse) Render

func (r *ErrorResponse) Render()

Render writes the response object to the given writer.

type JWTClaims

type JWTClaims struct {
	jwt.RegisteredClaims

	IsAuthenticated bool     `json:"authn"`
	Roles           []string `json:"roles"`
}

JWTClaims holds JWT claim data.

func ParseJWTClaims

func ParseJWTClaims(ctx *gin.Context, claims jwt.Claims) (*JWTClaims, error)

ParseJWTClaims takes the given claims interface and turns it into a JWTClaims object.

Note that this function only parses claims, it does not validate the presense of specific claims or their values.

The following errors are returned by this function: APITokenInvalid

func (*JWTClaims) Valid

func (c *JWTClaims) Valid() error

Valid checks to see if the JWT claims are valid or not.

Directories

Path Synopsis
auth
rooms

Jump to

Keyboard shortcuts

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