<commit_before>package authentication

import (
	log "github.com/Sirupsen/logrus"

	"fmt"
	"github.com/SpectoLabs/hoverfly/authentication/backends"
	jwt "github.com/dgrijalva/jwt-go"
	"net/http"
)

type AuthMiddleware struct {
	AB        backends.AuthBackend
	SecretKey []byte
}

func GetNewAuthenticationMiddleware(authBackend backends.AuthBackend, secretKey []byte) *AuthMiddleware {
	return &AuthMiddleware{AB: authBackend, SecretKey: secretKey}
}

func (a *AuthMiddleware) RequireTokenAuthentication(rw http.ResponseWriter, req *http.Request, next http.HandlerFunc) {
	authBackend := InitJWTAuthenticationBackend(a.AB, a.SecretKey)

	token, err := jwt.ParseFromRequest(req, func(token *jwt.Token) (interface{}, error) {
		if _, ok := token.Method.(*jwt.SigningMethodHMAC); !ok {<commit_msg>AuthMiddleware updated to contain JWTExpirationDelta<commit_after>package authentication

import (
	log "github.com/Sirupsen/logrus"

	"fmt"
	"github.com/SpectoLabs/hoverfly/authentication/backends"
	jwt "github.com/dgrijalva/jwt-go"
	"net/http"
)

type AuthMiddleware struct {
	AB                 backends.AuthBackend
	SecretKey          []byte
	JWTExpirationDelta int
}

func GetNewAuthenticationMiddleware(authBackend backends.AuthBackend, secretKey []byte) *AuthMiddleware {
	return &AuthMiddleware{AB: authBackend, SecretKey: secretKey}
}

func (a *AuthMiddleware) RequireTokenAuthentication(rw http.ResponseWriter, req *http.Request, next http.HandlerFunc) {
	authBackend := InitJWTAuthenticationBackend(a.AB, a.SecretKey)

	token, err := jwt.ParseFromRequest(req, func(token *jwt.Token) (interface{}, error) {
		if _, ok := token.Method.(*jwt.SigningMethodHMAC); !ok {
{'fraction_non_alphanumeric': 0.11384062312762133, 'fraction_numerical': 0.0, 'mean_word_length': 5.626984126984127, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4125002', 'n_tokens_mistral': 545, 'n_tokens_neox': 553, 'n_words': 108}