// GetAuthentication returns the authentication for a request
GetAuthentication returns the authentication for a request
// GetAuthentication returns the authentication for a request
func GetAuthentication(req *http.Request) *Claims {
	authHeader := req.Header.Get("Authorization")
	if strings.HasPrefix(authHeader, "Bearer ") {
		bearerToken := strings.TrimPrefix(authHeader, "Bearer ")
		token, err := jwt.ParseWithClaims(bearerToken, &Claims{}, func(token *jwt.Token) (interface{}, error) {
			if _, ok := token.Method.(*jwt.SigningMethodHMAC); !ok {
				return nil, fmt.Errorf("Unexpected signing method: %v", token.Header["alg"])
			}
			return hmacSecret, nil
		})
		if err != nil {
			logger.Warn("invalid token", zap.Error(err))
			return nil
		}
		if claims, ok := token.Claims.(*Claims); ok && token.Valid {
			return claims
		}
		logger.Warn("invalid token")
	}
	return nil
}
func GetAuthentication ( req * http . Request ) * Claims { authHeader := req . Header . Get ( " " ) if strings . HasPrefix ( authHeader , " " ) { bearerToken := strings . TrimPrefix ( authHeader , " " ) token , err := jwt . ParseWithClaims ( bearerToken , & Claims { } , func ( token * jwt . Token ) ( interface { } , error ) { if _ , ok := token . Method . ( * jwt . SigningMethodHMAC ) ; ! ok { return nil , fmt . Errorf ( " " , token . Header [ " " ] ) } return hmacSecret , nil } ) if err != nil { logger . Warn ( " " , zap . Error ( err ) ) return nil } if claims , ok := token . Claims . ( * Claims ) ; ok && token . Valid { return claims } logger . Warn ( " " ) } return nil }
GetAuthentication returns the authentication for a request
GetAuthentication returns the authentication for a request