func (h *jwtAuthorizationHandler) check(job rest.Job) (bool, error) {
	var token jwt.JWT
	var err error
	switch {
	case h.cache != nil && h.key != nil:
		token, err = jwt.VerifyCachedFromJob(job, h.cache, h.key)
	case h.cache != nil && h.key == nil:
		token, err = jwt.DecodeCachedFromJob(job, h.cache)
	case h.cache == nil && h.key != nil:
		token, err = jwt.VerifyFromJob(job, h.key)
	default:
		token, err = jwt.DecodeFromJob(job)
	}
	// Now do the checks.
	if err != nil {
		return h.deny(job, rest.StatusUnauthorized, err.Error())
	}
	if token == nil {
		return h.deny(job, rest.StatusUnauthorized, "no JSON Web Token")
	}
	if !token.IsValid(h.leeway) {
		return h.deny(job, rest.StatusForbidden, "JSON Web Token claims 'nbf' and/or 'exp' are not valid")
	}
	if h.gatekeeper != nil {
		err := h.gatekeeper(job, token.Claims())
		if err != nil {
			return h.deny(job, rest.StatusUnauthorized, "access rejected by gatekeeper: "+err.Error())
		}
	}
	// All fine, store token in context.
	job.EnhanceContext(func(ctx context.Context) context.Context {
		return jwt.NewContext(ctx, token)
	})
	return true, nil
}
// check is used by all methods to check the token.
check is used by all methods to check the token.
// check is used by all methods to check the token .
func (h *jwtAuthorizationHandler) check(job rest.Job) (bool, error) {
	var token jwt.JWT
	var err error
	switch {
	case h.cache != nil && h.key != nil:
		token, err = jwt.VerifyCachedFromJob(job, h.cache, h.key)
	case h.cache != nil && h.key == nil:
		token, err = jwt.DecodeCachedFromJob(job, h.cache)
	case h.cache == nil && h.key != nil:
		token, err = jwt.VerifyFromJob(job, h.key)
	default:
		token, err = jwt.DecodeFromJob(job)
	}
	if err != nil {
		return h.deny(job, rest.StatusUnauthorized, err.Error())
	}
	if token == nil {
		return h.deny(job, rest.StatusUnauthorized, "no JSON Web Token")
	}
	if !token.IsValid(h.leeway) {
		return h.deny(job, rest.StatusForbidden, "JSON Web Token claims 'nbf' and/or 'exp' are not valid")
	}
	if h.gatekeeper != nil {
		err := h.gatekeeper(job, token.Claims())
		if err != nil {
			return h.deny(job, rest.StatusUnauthorized, "access rejected by gatekeeper: "+err.Error())
		}
	}
	job.EnhanceContext(func(ctx context.Context) context.Context {
		return jwt.NewContext(ctx, token)
	})
	return true, nil
}
func ( h * jwtAuthorizationHandler ) check ( job rest . Job ) ( bool , error ) { var token jwt . JWT var err error switch { case h . cache != nil && h . key != nil : token , err = jwt . VerifyCachedFromJob ( job , h . cache , h . key ) case h . cache != nil && h . key == nil : token , err = jwt . DecodeCachedFromJob ( job , h . cache ) case h . cache == nil && h . key != nil : token , err = jwt . VerifyFromJob ( job , h . key ) default : token , err = jwt . DecodeFromJob ( job ) } if err != nil { return h . deny ( job , rest . StatusUnauthorized , err . Error ( ) ) } if token == nil { return h . deny ( job , rest . StatusUnauthorized , " " ) } if ! token . IsValid ( h . leeway ) { return h . deny ( job , rest . StatusForbidden , " " ) } if h . gatekeeper != nil { err := h . gatekeeper ( job , token . Claims ( ) ) if err != nil { return h . deny ( job , rest . StatusUnauthorized , " " + err . Error ( ) ) } } job . EnhanceContext ( func ( ctx context . Context ) context . Context { return jwt . NewContext ( ctx , token ) } ) return true , nil }
check is used by all methods to check the token.
check is used by all methods to check the token .
// Now do the checks. // All fine, store token in context.