This commit is contained in:
DeveloperDurp 2024-09-02 13:50:47 -05:00
parent 9f6d8ac621
commit 73830d57b8
2 changed files with 8 additions and 8 deletions

View file

@ -4,9 +4,8 @@ import (
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
"gitlab.com/developerdurp/durpify/logger"
"net/http" "net/http"
"gitlab.com/developerdurp/logger"
) )
type BasicMessage struct { type BasicMessage struct {

View file

@ -3,13 +3,14 @@ package middleware
import ( import (
"context" "context"
"errors" "errors"
"gitlab.com/developerdurp/durpify/handlers"
"gitlab.com/developerdurp/durpify/logger"
"net/http" "net/http"
"strings" "strings"
"time" "time"
"github.com/MicahParks/keyfunc" "github.com/MicahParks/keyfunc"
"github.com/golang-jwt/jwt/v4" "github.com/golang-jwt/jwt/v4"
"gitlab.com/developerdurp/logger"
) )
func InitAuthMiddleware(allowedGroups []string, jwks string) *AuthConfig { func InitAuthMiddleware(allowedGroups []string, jwks string) *AuthConfig {
@ -35,7 +36,7 @@ func (cfg *AuthConfig) AuthMiddleware(next http.Handler) http.Handler {
tokenString, err := getToken(w) tokenString, err := getToken(w)
if err != nil { if err != nil {
resp := stdmodels.NewFailureResponse( resp := handlers.NewFailureResponse(
err.Error(), err.Error(),
http.StatusUnauthorized, http.StatusUnauthorized,
[]string{}, []string{},
@ -45,7 +46,7 @@ func (cfg *AuthConfig) AuthMiddleware(next http.Handler) http.Handler {
token, err := cfg.validateToken(tokenString) token, err := cfg.validateToken(tokenString)
if err != nil { if err != nil {
resp := stdmodels.NewFailureResponse( resp := handlers.NewFailureResponse(
"Failed to Validate Token", "Failed to Validate Token",
http.StatusUnauthorized, http.StatusUnauthorized,
[]string{err.Error()}, []string{err.Error()},
@ -55,7 +56,7 @@ func (cfg *AuthConfig) AuthMiddleware(next http.Handler) http.Handler {
claims, ok := token.Claims.(jwt.MapClaims) claims, ok := token.Claims.(jwt.MapClaims)
if !ok { if !ok {
resp := stdmodels.NewFailureResponse( resp := handlers.NewFailureResponse(
"Invalid Authorization token claim", "Invalid Authorization token claim",
http.StatusUnauthorized, http.StatusUnauthorized,
[]string{}, []string{},
@ -66,7 +67,7 @@ func (cfg *AuthConfig) AuthMiddleware(next http.Handler) http.Handler {
groupsClaim, ok := claims["groups"].([]interface{}) groupsClaim, ok := claims["groups"].([]interface{})
if !ok { if !ok {
resp := stdmodels.NewFailureResponse( resp := handlers.NewFailureResponse(
"Missing or invalid groups in the token", "Missing or invalid groups in the token",
http.StatusUnauthorized, http.StatusUnauthorized,
[]string{}, []string{},
@ -95,7 +96,7 @@ func (cfg *AuthConfig) AuthMiddleware(next http.Handler) http.Handler {
} }
if !isAllowed { if !isAllowed {
resp := stdmodels.NewFailureResponse( resp := handlers.NewFailureResponse(
"Unauthorized to use this endpoint", "Unauthorized to use this endpoint",
http.StatusUnauthorized, http.StatusUnauthorized,
[]string{}, []string{},